finish box1 exercise

This commit is contained in:
lukaszKielar 2020-06-29 22:44:40 +02:00
parent 13e1faf060
commit 79b992dec4

View File

@ -16,25 +16,26 @@
// //
// Execute `rustlings hint box1` for hints :) // Execute `rustlings hint box1` for hints :)
// I AM NOT DONE
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub enum List { pub enum List {
Cons(i32, List), Cons(i32, Box<List>),
Nil, Nil,
} }
fn main() { fn main() {
println!("This is an empty cons list: {:?}", create_empty_list()); println!("This is an empty cons list: {:?}", create_empty_list());
println!("This is a non-empty cons list: {:?}", create_non_empty_list()); println!(
"This is a non-empty cons list: {:?}",
create_non_empty_list()
);
} }
pub fn create_empty_list() -> List { pub fn create_empty_list() -> List {
unimplemented!() List::Nil
} }
pub fn create_non_empty_list() -> List { pub fn create_non_empty_list() -> List {
unimplemented!() List::Cons(0, Box::new(create_empty_list()))
} }
#[cfg(test)] #[cfg(test)]