File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -716,6 +716,17 @@ implement the function themselves.
716
716
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#default-implementations
717
717
"""
718
718
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
+
719
730
# QUIZ 3
720
731
721
732
[[exercises ]]
You can’t perform that action at this time.
0 commit comments