File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed
Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 1818//
1919// Execute `rustlings hint box1` or use the `hint` watch subcommand for a hint.
2020
21- // I AM NOT DONE
2221
2322#[ derive( PartialEq , Debug ) ]
2423pub enum List {
25- Cons ( i32 , List ) ,
24+ Cons ( i32 , Box < List > ) ,
2625 Nil ,
2726}
2827
@@ -35,11 +34,11 @@ fn main() {
3534}
3635
3736pub fn create_empty_list ( ) -> List {
38- todo ! ( )
37+ List :: Nil
3938}
4039
4140pub fn create_non_empty_list ( ) -> List {
42- todo ! ( )
41+ List :: Cons ( 0 , Box :: new ( List :: Nil ) )
4342}
4443
4544#[ cfg( test) ]
Original file line number Diff line number Diff line change 1010//
1111// Execute `rustlings hint rc1` or use the `hint` watch subcommand for a hint.
1212
13- // I AM NOT DONE
13+
1414
1515use std:: rc:: Rc ;
1616
@@ -60,17 +60,17 @@ fn main() {
6060 jupiter. details ( ) ;
6161
6262 // TODO
63- let saturn = Planet :: Saturn ( Rc :: new ( Sun { } ) ) ;
63+ let saturn = Planet :: Saturn ( Rc :: clone ( & sun ) ) ;
6464 println ! ( "reference count = {}" , Rc :: strong_count( & sun) ) ; // 7 references
6565 saturn. details ( ) ;
6666
6767 // TODO
68- let uranus = Planet :: Uranus ( Rc :: new ( Sun { } ) ) ;
68+ let uranus = Planet :: Uranus ( Rc :: clone ( & sun ) ) ;
6969 println ! ( "reference count = {}" , Rc :: strong_count( & sun) ) ; // 8 references
7070 uranus. details ( ) ;
7171
7272 // TODO
73- let neptune = Planet :: Neptune ( Rc :: new ( Sun { } ) ) ;
73+ let neptune = Planet :: Neptune ( Rc :: clone ( & sun ) ) ;
7474 println ! ( "reference count = {}" , Rc :: strong_count( & sun) ) ; // 9 references
7575 neptune. details ( ) ;
7676
@@ -92,12 +92,15 @@ fn main() {
9292 println ! ( "reference count = {}" , Rc :: strong_count( & sun) ) ; // 4 references
9393
9494 // TODO
95+ drop ( earth) ;
9596 println ! ( "reference count = {}" , Rc :: strong_count( & sun) ) ; // 3 references
9697
9798 // TODO
99+ drop ( venus) ;
98100 println ! ( "reference count = {}" , Rc :: strong_count( & sun) ) ; // 2 references
99101
100102 // TODO
103+ drop ( mercury) ;
101104 println ! ( "reference count = {}" , Rc :: strong_count( & sun) ) ; // 1 reference
102105
103106 assert_eq ! ( Rc :: strong_count( & sun) , 1 ) ;
You can’t perform that action at this time.
0 commit comments