@@ -125,34 +125,34 @@ fn main() {
125125 println ! ( "{}" , "\n === Accessing nested data ===" . to_string( ) ) ;
126126
127127 print ! ( "Company: {}\n " , ( * ( * company. borrow( ) . as_ref( ) . unwrap( ) ) . name. borrow( ) . as_ref( ) . unwrap( ) ) ) ;
128- print ! ( "HQ Address: {}, {}, {} {}\n " , ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . headquarters. street, ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . headquarters. city, ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . headquarters. state, ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . headquarters. zip_code) ;
128+ print ! ( "HQ Address: {}, {}, {} {}\n " , ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . headquarters. borrow ( ) . as_ref ( ) . unwrap ( ) ) . street. borrow ( ) . as_ref ( ) . unwrap ( ) ) , ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . headquarters. borrow ( ) . as_ref ( ) . unwrap ( ) ) . city. borrow ( ) . as_ref ( ) . unwrap ( ) ) , ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . headquarters. borrow ( ) . as_ref ( ) . unwrap ( ) ) . state. borrow ( ) . as_ref ( ) . unwrap ( ) ) , ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . headquarters. borrow ( ) . as_ref ( ) . unwrap ( ) ) . zip_code. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
129129
130- print ! ( "Department: {}\n " , ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . name) ;
131- print ! ( "Department Budget: ${:.2}\n " , ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . budget) ;
130+ print ! ( "Department: {}\n " , ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . name. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
131+ print ! ( "Department Budget: ${:.2}\n " , ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . budget. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
132132
133- print ! ( "Manager: {} (Age: {})\n " , ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. name, ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. age) ;
133+ print ! ( "Manager: {} (Age: {})\n " , ( * ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. borrow ( ) . as_ref ( ) . unwrap ( ) ) . name. borrow ( ) . as_ref ( ) . unwrap ( ) ) , ( * ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. borrow ( ) . as_ref ( ) . unwrap ( ) ) . age. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
134134
135- print ! ( "Manager Email: {}\n " , ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. contact. email) ;
135+ print ! ( "Manager Email: {}\n " , ( * ( * ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. borrow ( ) . as_ref ( ) . unwrap ( ) ) . contact. borrow ( ) . as_ref ( ) . unwrap ( ) ) . email. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
136136
137- print ! ( "Manager Address: {}, {}\n " , ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. address. city, ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. address. state) ;
137+ print ! ( "Manager Address: {}, {}\n " , ( * ( * ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. borrow ( ) . as_ref ( ) . unwrap ( ) ) . address. borrow ( ) . as_ref ( ) . unwrap ( ) ) . city. borrow ( ) . as_ref ( ) . unwrap ( ) ) , ( * ( * ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . manager. borrow ( ) . as_ref ( ) . unwrap ( ) ) . address. borrow ( ) . as_ref ( ) . unwrap ( ) ) . state. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
138138
139139 // Iterate through employees
140140 println ! ( "{}" , "\n === Department employees ===" . to_string( ) ) ;
141141
142- for ( i, emp) in ( * ( * company. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . departments . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . employees . iter ( ) . enumerate ( ) {
143- print ! ( "Employee {}: {}\n " , i + 1 , emp. name) ;
144- print ! ( " Age: {}\n " , emp. age) ;
145- print ! ( " Email: {}\n " , emp. contact. email) ;
146- print ! ( " Phone: {}\n " , emp. contact. phone) ;
147- print ! ( " Address: {}, {}, {}\n " , emp. address. street, emp. address. city, emp. address. state) ;
142+ for ( i, emp) in ( * ( * ( * company. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . departments . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . employees . borrow ( ) . as_ref ( ) . unwrap ( ) ) . iter ( ) . enumerate ( ) {
143+ print ! ( "Employee {}: {}\n " , i + 1 , ( * emp. name. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
144+ print ! ( " Age: {}\n " , ( * emp. age. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
145+ print ! ( " Email: {}\n " , ( * ( * emp. contact. borrow ( ) . as_ref ( ) . unwrap ( ) ) . email. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
146+ print ! ( " Phone: {}\n " , ( * ( * emp. contact. borrow ( ) . as_ref ( ) . unwrap ( ) ) . phone. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
147+ print ! ( " Address: {}, {}, {}\n " , ( * ( * emp. address. borrow ( ) . as_ref ( ) . unwrap ( ) ) . street. borrow ( ) . as_ref ( ) . unwrap ( ) ) , ( * ( * emp. address. borrow ( ) . as_ref ( ) . unwrap ( ) ) . city. borrow ( ) . as_ref ( ) . unwrap ( ) ) , ( * ( * emp. address. borrow ( ) . as_ref ( ) . unwrap ( ) ) . state. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
148148 println ! ( ) ;
149149 }
150150
151151 // Nested maps
152152 println ! ( "{}" , "=== Nested maps ===" . to_string( ) ) ;
153153
154154 // Map of maps
155- let mut inventory = Rc :: new ( RefCell :: new ( Some ( HashMap :: < String , Rc < RefCell < Option < HashMap < String , i32 > > > > > :: from ( [ ( "electronics" . to_string ( ) , Rc :: new ( RefCell :: new ( Some ( ) ) ) ) , ( "furniture" . to_string ( ) , Rc :: new ( RefCell :: new ( Some ( ) ) ) ) , ( "supplies" . to_string ( ) , Rc :: new ( RefCell :: new ( Some ( ) ) ) ) ] ) ) ) ) ;
155+ let mut inventory = Rc :: new ( RefCell :: new ( Some ( HashMap :: < String , Rc < RefCell < Option < HashMap < String , i32 > > > > > :: from ( [ ( "electronics" . to_string ( ) , Rc :: new ( RefCell :: new ( Some ( /* ERROR: CompositeLit with nil Type - type inference failed */ unimplemented ! ( ) ) ) ) ) , ( "furniture" . to_string ( ) , Rc :: new ( RefCell :: new ( Some ( /* ERROR: CompositeLit with nil Type - type inference failed */ unimplemented ! ( ) ) ) ) ) , ( "supplies" . to_string ( ) , Rc :: new ( RefCell :: new ( Some ( /* ERROR: CompositeLit with nil Type - type inference failed */ unimplemented ! ( ) ) ) ) ) ] ) ) ) ) ;
156156
157157 println ! ( "{}" , "Inventory:" . to_string( ) ) ;
158158 for ( category, items) in ( * inventory. borrow ( ) . as_ref ( ) . unwrap ( ) ) . clone ( ) {
@@ -170,7 +170,7 @@ fn main() {
170170 println ! ( "{}" , "\n === Nested slices ===" . to_string( ) ) ;
171171
172172 // Matrix (slice of slices)
173- let mut matrix = Rc :: new ( RefCell :: new ( Some ( vec ! [ , , ] ) ) ) ;
173+ let mut matrix = Rc :: new ( RefCell :: new ( Some ( vec ! [ Rc :: new ( RefCell :: new ( Some ( vec! [ 1 , 2 , 3 ] ) ) ) , Rc :: new ( RefCell :: new ( Some ( vec! [ 4 , 5 , 6 ] ) ) ) , Rc :: new ( RefCell :: new ( Some ( vec! [ 7 , 8 , 9 ] ) ) ) ] ) ) ) ;
174174
175175 println ! ( "{}" , "Matrix:" . to_string( ) ) ;
176176 for ( i, row) in ( * matrix. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . iter ( ) . enumerate ( ) {
@@ -189,7 +189,7 @@ fn main() {
189189 print ! ( "Center element: {}\n " , ( * centerElement. borrow_mut( ) . as_mut( ) . unwrap( ) ) ) ;
190190
191191 // 3D slice
192- let mut cube = Rc :: new ( RefCell :: new ( Some ( vec ! [ , ] ) ) ) ;
192+ let mut cube = Rc :: new ( RefCell :: new ( Some ( vec ! [ Rc :: new ( RefCell :: new ( Some ( vec! [ Rc :: new ( RefCell :: new ( Some ( vec! [ 1 , 2 ] ) ) ) , Rc :: new ( RefCell :: new ( Some ( vec! [ 3 , 4 ] ) ) ) ] ) ) ) , Rc :: new ( RefCell :: new ( Some ( vec! [ Rc :: new ( RefCell :: new ( Some ( vec! [ 5 , 6 ] ) ) ) , Rc :: new ( RefCell :: new ( Some ( vec! [ 7 , 8 ] ) ) ) ] ) ) ) ] ) ) ) ;
193193
194194 println ! ( "{}" , "\n 3D Cube:" . to_string( ) ) ;
195195 for ( i, layer) in ( * cube. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . iter ( ) . enumerate ( ) {
@@ -209,21 +209,21 @@ fn main() {
209209 let mut canvas = Rc :: new ( RefCell :: new ( Some ( Canvas { name : Rc :: new ( RefCell :: new ( Some ( "My Drawing" . to_string ( ) ) ) ) , shapes : Rc :: new ( RefCell :: new ( Some ( Rc :: new ( RefCell :: new ( Some ( vec ! [ Circle { radius: Rc :: new( RefCell :: new( Some ( 5.0 ) ) ) } , Rectangle { width: Rc :: new( RefCell :: new( Some ( 10.0 ) ) ) , height: Rc :: new( RefCell :: new( Some ( 8.0 ) ) ) } , Circle { radius: Rc :: new( RefCell :: new( Some ( 3.0 ) ) ) } ] ) ) ) ) ) ) } ) ) ) ;
210210
211211 print ! ( "Canvas: {}\n " , ( * ( * canvas. borrow( ) . as_ref( ) . unwrap( ) ) . name. borrow( ) . as_ref( ) . unwrap( ) ) ) ;
212- for ( i, shape) in ( * canvas. borrow ( ) . as_ref ( ) . unwrap ( ) ) . shapes . iter ( ) . enumerate ( ) {
212+ for ( i, shape) in ( * ( * canvas. borrow ( ) . as_ref ( ) . unwrap ( ) ) . shapes . borrow ( ) . as_ref ( ) . unwrap ( ) ) . iter ( ) . enumerate ( ) {
213213 print ! ( "Shape {}: {}\n " , i + 1 , ( * shape. draw( ) . borrow( ) . as_ref( ) . unwrap( ) ) ) ;
214214 }
215215
216216 // Modify nested structures
217217 println ! ( "{}" , "\n === Modifying nested structures ===" . to_string( ) ) ;
218218
219219 // Update employee contact
220- { let new_val =
"[email protected] " . to_string ( ) ; * ( * ( * ( * company
. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . departments . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . employees . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . contact . email . borrow_mut ( ) =
Some ( new_val
) ; } ; 221- print ! ( "Updated employee email: {}\n " , ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . employees. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . contact. email) ;
220+ { let new_val =
"[email protected] " . to_string ( ) ; * ( * ( * ( * ( * company
. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . departments . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . employees . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . contact . borrow ( ) . as_ref ( ) . unwrap ( ) ) . email . borrow_mut ( ) =
Some ( new_val
) ; } ; 221+ print ! ( "Updated employee email: {}\n " , ( * ( * ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . employees. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . contact. borrow ( ) . as_ref ( ) . unwrap ( ) ) . email. borrow ( ) . as_ref ( ) . unwrap ( ) ) ) ;
222222
223223 // Add new employee
224224 let mut newEmployee =
Rc :: new ( RefCell :: new ( Some ( Person { name : Rc :: new ( RefCell :: new ( Some ( "Dave Newbie" . to_string ( ) ) ) ) , age : Rc :: new ( RefCell :: new ( Some ( 25 ) ) ) , address : Rc :: new ( RefCell :: new ( Some ( Address { street : Rc :: new ( RefCell :: new ( Some ( "999 New St" . to_string ( ) ) ) ) , city : Rc :: new ( RefCell :: new ( Some ( "Newtown" . to_string ( ) ) ) ) , state : Rc :: new ( RefCell :: new ( Some ( "CA" . to_string ( ) ) ) ) , zip_code : Rc :: new ( RefCell :: new ( Some ( "90214" . to_string ( ) ) ) ) , country : Rc :: new ( RefCell :: new ( Some ( "USA" . to_string ( ) ) ) ) } ) ) ) , contact : Rc :: new ( RefCell :: new ( Some ( Contact { email : Rc :: new ( RefCell :: new ( Some ( "[email protected] " . to_string ( ) ) ) ) , phone : Rc :: new ( RefCell :: new ( Some ( "555-0004" . to_string ( ) ) ) ) } ) ) ) } ) ) ) ; 225225
226- { ( * ( * ( * company. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . departments . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . employees . borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . push ( ( * newEmployee. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) ) ; ( * ( * company. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . departments . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . employees . clone ( ) } ;
226+ { ( * ( * ( * ( * company. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . departments . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . employees . borrow ( ) . as_ref ( ) . unwrap ( ) ) . borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . push ( ( * newEmployee. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) ) ; ( * ( * ( * company. borrow_mut ( ) . as_mut ( ) . unwrap ( ) ) . departments . borrow ( ) . as_ref ( ) . unwrap ( ) ) [ 0 as usize ] . clone ( ) . employees . borrow ( ) . as_ref ( ) . unwrap ( ) ) . clone ( ) } ;
227227 print ! ( "Added new employee: {}\n " , ( * ( * newEmployee. borrow( ) . as_ref( ) . unwrap( ) ) . name. borrow( ) . as_ref( ) . unwrap( ) ) ) ;
228228 print ! ( "Total employees now: {}\n " , ( * ( * ( * company. borrow_mut( ) . as_mut( ) . unwrap( ) ) . departments. borrow( ) . as_ref( ) . unwrap( ) ) [ 0 as usize ] . clone( ) . employees. borrow( ) . as_ref( ) . unwrap( ) ) . len( ) ) ;
229229}
0 commit comments