Skip to content

Commit 63b0c7e

Browse files
95swhitemanyinsects
authored andcommitted
feat: add traits5.rs exercise
1 parent 599d634 commit 63b0c7e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

exercises/traits/traits5.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// traits5.rs
2+
//
3+
// Your task is to replace the '??' sections so the code compiles.
4+
// Don't change any line other than 27.
5+
6+
// I AM NOT DONE
7+
8+
pub trait SomeTrait {
9+
fn some_function(&self) -> bool {
10+
true
11+
}
12+
}
13+
14+
pub trait OtherTrait {
15+
fn other_function(&self) -> bool {
16+
true
17+
}
18+
}
19+
20+
struct SomeStruct {
21+
name: String,
22+
}
23+
24+
impl SomeTrait for SomeStruct {}
25+
impl OtherTrait for SomeStruct {}
26+
27+
fn some_func(item: ??) -> bool {
28+
item.some_function() && item.other_function()
29+
}
30+
31+
fn main() {}

info.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,17 @@ Instead of using concrete types as parameters you can use traits. Try replacing
727727
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
728728
"""
729729

730+
[[exercises]]
731+
name = "traits5"
732+
path = "exercises/traits/traits5.rs"
733+
mode = "compile"
734+
hint = """
735+
To ensure a paramter implements multiple traits use the '+ syntax'. Try replacing the
736+
'??' with 'impl <> + <>'.
737+
738+
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#specifying-multiple-trait-bounds-with-the--syntax
739+
"""
740+
730741
# QUIZ 3
731742

732743
[[exercises]]

0 commit comments

Comments
 (0)