rustlings
rustlings copied to clipboard
Alternative `traits5` solution?
The hint for traits5
implies the solution should involve specifying multiple trait bounds:
❯ rustlings hint traits5
To ensure a paramter implements multiple traits use the '+ syntax'. Try replacing the
'??' with 'impl <> + <>'.
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#specifying-multiple-trait-bounds-with-the--syntax
with the solution being:
// YOU MAY ONLY CHANGE THE NEXT LINE
fn some_func(item: impl SomeTrait + OtherTrait) -> bool {
However, it can also be solved as such:
// YOU MAY ONLY CHANGE THE NEXT LINE
fn some_func(item: SomeStruct) -> bool {
~/projects/rustlings main*
❯ rustlings run traits5
✓ Successfully ran exercises/traits/traits5.rs
My first attempt (prior to running rustlings hint traits5
) was the non-multiple-trait-bound solution, and without checking the hint after that, I think I would have just carried on without learning the concept this exercise teaches. This just could be a lack of knowledge on my part though, and I don't know if this is just another intended solution for this exercise.
❯ rustc --version
rustc 1.62.0 (a8314ef7d 2022-06-27)
❯ rustlings --version
v5.0.0
❯ ls -la
total 272
drwxr-xr-x 8 greg greg 4096 Jul 18 19:48 .
drwxr-xr-x 12 greg greg 4096 Jul 18 18:19 ..
-rw-r--r-- 1 greg greg 37296 Jul 18 18:19 .all-contributorsrc
-rw-r--r-- 1 greg greg 102 Jul 18 18:19 .editorconfig
drwxr-xr-x 8 greg greg 4096 Jul 18 18:19 .git
drwxr-xr-x 3 greg greg 4096 Jul 18 18:19 .github
-rw-r--r-- 1 greg greg 139 Jul 18 18:19 .gitignore
-rw-r--r-- 1 greg greg 150 Jul 18 18:19 .gitpod.yml
-rw-r--r-- 1 greg greg 104 Jul 18 18:19 .replit
-rw-r--r-- 1 greg greg 44773 Jul 18 18:19 AUTHORS.md
-rw-r--r-- 1 greg greg 41137 Jul 18 18:19 CHANGELOG.md
-rw-r--r-- 1 greg greg 4171 Jul 18 18:19 CONTRIBUTING.md
-rw-r--r-- 1 greg greg 16506 Jul 18 18:28 Cargo.lock
-rw-r--r-- 1 greg greg 497 Jul 18 18:19 Cargo.toml
-rw-r--r-- 1 greg greg 1095 Jul 18 18:19 LICENSE
-rw-r--r-- 1 greg greg 5799 Jul 18 18:19 README.md
drwxr-xr-x 25 greg greg 4096 Jul 18 18:19 exercises
-rw-r--r-- 1 greg greg 40802 Jul 18 18:19 info.toml
-rw-r--r-- 1 greg greg 3022 Jul 18 18:19 install.ps1
-rwxr-xr-x 1 greg greg 4591 Jul 18 18:19 install.sh
drwxr-xr-x 2 greg greg 4096 Jul 18 18:19 src
drwxr-xr-x 5 greg greg 4096 Jul 18 18:28 target
drwxr-xr-x 3 greg greg 4096 Jul 18 18:19 tests
❯ hostnamectl
Operating System: Arch Linux
Kernel: Linux 5.17.5-arch1-1
Architecture: x86-64