Skip to content

Commit 599d634

Browse files
95swhitemanyinsects
authored andcommitted
feat: Add traits4.rs exercise
1 parent f43c6d7 commit 599d634

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

exercises/traits/traits4.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// traits4.rs
2+
//
3+
// Your task is to replace the '??' sections so the code compiles.
4+
// Don't change any line other than 21.
5+
6+
// I AM NOT DONE
7+
8+
pub trait Licensed {
9+
fn licensing_info(&self) -> String {
10+
"some information".to_string()
11+
}
12+
}
13+
14+
struct SomeSoftware {}
15+
16+
struct OtherSoftware {}
17+
18+
impl Licensed for SomeSoftware {}
19+
impl Licensed for OtherSoftware {}
20+
21+
fn compare_license_types(software: ??, software_two: ??) -> bool {
22+
software.licensing_info() == software_two.licensing_info()
23+
}
24+
25+
#[cfg(test)]
26+
mod tests {
27+
use super::*;
28+
29+
#[test]
30+
fn compare_license_information() {
31+
let some_software = SomeSoftware {};
32+
let other_software = OtherSoftware {};
33+
34+
assert!(compare_license_types(some_software, other_software));
35+
}
36+
37+
#[test]
38+
fn compare_license_information_backwards() {
39+
let some_software = SomeSoftware {};
40+
let other_software = OtherSoftware {};
41+
42+
assert!(compare_license_types(other_software, some_software));
43+
}
44+
}

info.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,17 @@ implement the function themselves.
716716
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#default-implementations
717717
"""
718718

719+
[[exercises]]
720+
name = "traits4"
721+
path = "exercises/traits/traits4.rs"
722+
mode = "test"
723+
hint = """
724+
Instead of using concrete types as parameters you can use traits. Try replacing the
725+
'??' with 'impl <what goes here?>'
726+
727+
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
728+
"""
729+
719730
# QUIZ 3
720731

721732
[[exercises]]

0 commit comments

Comments
 (0)