mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-07 03:09:19 +00:00
finish box1 exercise
This commit is contained in:
parent
13e1faf060
commit
79b992dec4
@ -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)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user