mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 00:00:03 +03:00
feat: add traits5.rs exercise
This commit is contained in:
parent
599d634ee2
commit
63b0c7e399
31
exercises/traits/traits5.rs
Normal file
31
exercises/traits/traits5.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// traits5.rs
|
||||||
|
//
|
||||||
|
// Your task is to replace the '??' sections so the code compiles.
|
||||||
|
// Don't change any line other than 27.
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
pub trait SomeTrait {
|
||||||
|
fn some_function(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait OtherTrait {
|
||||||
|
fn other_function(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SomeStruct {
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SomeTrait for SomeStruct {}
|
||||||
|
impl OtherTrait for SomeStruct {}
|
||||||
|
|
||||||
|
fn some_func(item: ??) -> bool {
|
||||||
|
item.some_function() && item.other_function()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
11
info.toml
11
info.toml
|
@ -727,6 +727,17 @@ Instead of using concrete types as parameters you can use traits. Try replacing
|
||||||
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
[[exercises]]
|
||||||
|
name = "traits5"
|
||||||
|
path = "exercises/traits/traits5.rs"
|
||||||
|
mode = "compile"
|
||||||
|
hint = """
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
# QUIZ 3
|
# QUIZ 3
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
|
|
Loading…
Reference in a new issue