File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed
Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ ### Strings
2+
3+ Rust has three struct types: a classic c struct, a tuple struct, and a unit struct.
4+
5+ #### Book Sections
6+
7+ - [ Structures] ( https://doc.rust-lang.org/rust-by-example/custom_types/structs.html )
Original file line number Diff line number Diff line change 1+ // structs1.rs
2+ // Address all the TODOs to make the tests pass!
3+
4+ struct ColorClassicStruct {
5+ // TODO: Something goes here
6+ }
7+
8+ struct ColorTupleStruct ( /* TODO: Something goes here */ ) ;
9+
10+ struct ColorUnitStruct ;
11+
12+ #[ cfg( test) ]
13+ mod tests {
14+ use super :: * ;
15+
16+ #[ test]
17+ fn classic_c_structs ( ) {
18+ // TODO: Instantiate a classic c struct!
19+ // let green =
20+
21+ assert_eq ! ( green. name, "green" ) ;
22+ assert_eq ! ( green. hex, "#00FF00" ) ;
23+ }
24+
25+ #[ test]
26+ fn tuple_structs ( ) {
27+ // TODO: Instantiate a tuple struct!
28+ // For more fun, use the field initialization shorthand.
29+ // let green =
30+
31+ assert_eq ! ( green. 0 , "green" ) ;
32+ assert_eq ! ( green. 1 , "#00FF00" ) ;
33+ }
34+
35+ #[ test]
36+ fn unit_structs ( ) {
37+ // TODO: Instantiate a unit struct!
38+ // let green =
39+
40+ if let ColorUnitStruct = green {
41+ assert ! ( true ) ;
42+ } else {
43+ assert ! ( false ) ;
44+ }
45+ }
46+ }
Original file line number Diff line number Diff line change @@ -76,6 +76,12 @@ mode = "compile"
7676path = " exercises/primitive_types/primitive_types6.rs"
7777mode = " compile"
7878
79+ # STRUCTS
80+
81+ [[exercises ]]
82+ path = " exercises/structs/structs1.rs"
83+ mode = " test"
84+
7985# TESTS
8086
8187[[exercises ]]
You can’t perform that action at this time.
0 commit comments