Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created February 11, 2019 07:54
Show Gist options
  • Save rust-play/e54d15602fa8a1d8f7a17521f85d1133 to your computer and use it in GitHub Desktop.
Save rust-play/e54d15602fa8a1d8f7a17521f85d1133 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
println!("Hello, world!");
}
struct Stack{
length:u32,
list:Option<Box<List>>,
}
struct List{
value:i32,
next:Option<Box<List>>,
}
impl Stack{
fn new()->Self{
Stack{
length:0,
list:None,
}
}
fn push(&mut self,value:i32){
let new_list=Box::new(
List{
value:value,
next:self.list,
}
);
self.list=Some(new_list);
self.length=self.length+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment