jweinst1
4/2/2017 - 11:41 PM

int stack object in rust

int stack object in rust

//example of struct with methods in Rust
//meant to simulate stack machine


struct IntStack {
    items:Vec<i32>
}

impl IntStack {
    //constructor function for IntStack
    fn new() -> IntStack {
        IntStack{items:vec![]}
    }
    
    fn push(&mut self, num: i32) {
        self.items.push(num);
    }
}


fn main() {
   let mut a = IntStack::new();
   for i in 0..10 {
       a.push(i);
   }
   println!("The first item in the stack is {}", a.items[0]);
}