File tree Expand file tree Collapse file tree 2 files changed +29
-11
lines changed
exercises/standard_library_types Expand file tree Collapse file tree 2 files changed +29
-11
lines changed Original file line number Diff line number Diff line change 12
12
// Step 1: use a `Box` in the enum definition to make the code compile
13
13
// Step 2: create both empty and non-empty cons lists of by replacing `unimplemented!()`
14
14
//
15
+ // Note: the tests should not be changed
16
+ //
15
17
// Execute `rustlings hint box1` for hints :)
16
18
17
19
// I AM NOT DONE
18
20
19
21
#[ derive( PartialEq , Debug ) ]
20
- enum List {
22
+ pub enum List {
21
23
Cons ( i32 , List ) ,
22
24
Nil ,
23
25
}
24
26
25
27
fn main ( ) {
26
- let empty_list = unimplemented ! ( ) ;
27
- println ! ( "This is an empty cons list: {:?}" , empty_list) ;
28
+ println ! ( "This is an empty cons list: {:?}" , create_empty_list( ) ) ;
29
+ println ! ( "This is a non-empty cons list: {:?}" , create_non_empty_list( ) ) ;
30
+ }
31
+
32
+ pub fn create_empty_list ( ) -> List {
33
+ unimplemented ! ( )
34
+ }
35
+
36
+ pub fn create_non_empty_list ( ) -> List {
37
+ unimplemented ! ( )
38
+ }
39
+
40
+ #[ cfg( test) ]
41
+ mod tests {
42
+ use super :: * ;
28
43
29
- let non_empty_list = unimplemented ! ( ) ;
30
- println ! ( "This is a non-empty cons list: {:?}" , non_empty_list) ;
44
+ #[ test]
45
+ fn test_create_empty_list ( ) {
46
+ assert_eq ! ( List :: Nil , create_empty_list( ) )
47
+ }
31
48
32
- // Do not change these
33
- assert_eq ! ( List :: Nil , empty_list) ;
34
- assert_ne ! ( empty_list, non_empty_list) ;
49
+ #[ test]
50
+ fn test_create_non_empty_list ( ) {
51
+ assert_ne ! ( create_empty_list( ) , create_non_empty_list( ) )
52
+ }
35
53
}
Original file line number Diff line number Diff line change @@ -617,17 +617,17 @@ hint = """
617
617
[[exercises ]]
618
618
name = " box1"
619
619
path = " exercises/standard_library_types/box1.rs"
620
- mode = " compile "
620
+ mode = " test "
621
621
hint = """
622
622
Step 1
623
623
The compiler's message should help: since we cannot store the value of the actual type
624
624
when working with recursive types, we need to store a reference (pointer) to its value.
625
- We should therefore place our `List` inside a `Box`. More details in the book here:
625
+ We should, therefore, place our `List` inside a `Box`. More details in the book here:
626
626
https://doc.rust-lang.org/book/ch15-01-box.html#enabling-recursive-types-with-boxes
627
627
628
628
Step 2
629
629
Creating an empty list should be fairly straightforward (hint: peek at the assertions).
630
- For a non-empty list keep in mind that wee want to use our Cons "list builder".
630
+ For a non-empty list keep in mind that we want to use our Cons "list builder".
631
631
Although the current list is one of integers (i32), feel free to change the definition
632
632
and try other types!
633
633
"""
You can’t perform that action at this time.
0 commit comments