From aca9505dfc6c5869dba63d2f5186b7689bd80a6c Mon Sep 17 00:00:00 2001 From: vipin joshi Date: Sun, 30 Jun 2024 10:24:53 +0530 Subject: [PATCH] box smart pointer --- exercises/19_smart_pointers/box1.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/exercises/19_smart_pointers/box1.rs b/exercises/19_smart_pointers/box1.rs index 513e7da..65aaf99 100644 --- a/exercises/19_smart_pointers/box1.rs +++ b/exercises/19_smart_pointers/box1.rs @@ -18,14 +18,16 @@ // // Execute `rustlings hint box1` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE #[derive(PartialEq, Debug)] + pub enum List { - Cons(i32, List), + Cons(i32, Box), Nil, } +use crate::List::{Cons, Nil}; + fn main() { println!("This is an empty cons list: {:?}", create_empty_list()); println!( @@ -35,11 +37,11 @@ fn main() { } pub fn create_empty_list() -> List { - todo!() + Nil } pub fn create_non_empty_list() -> List { - todo!() + Cons(1, Box::new(Cons(2, Box::new(Cons(3, Box::new(Nil)))))) } #[cfg(test)]