[][src]Struct drumatech::structure::Stack

pub struct Stack<T> {
    pub sp: usize,
    pub contents: Vec<T>,
}

Fields

sp: usizecontents: Vec<T>

Methods

impl<T> Stack<T>[src]

pub fn new(contents: Vec<T>) -> Stack<T>[src]

the constructor is need tuple for initializing Stack

Examples

extern crate drumatech;
use drumatech::structure;
let mut stack = structure::Stack::new(vec![1,3,5,7,9]);

pub fn allocate(cap: usize) -> Stack<T>[src]

the constructor is need capacity for allocating memories for Stack\ndon't forget to annotate type

Examples

extern crate drumatech;
use drumatech::structure;
let mut stack : structure::Stack<u8> = structure::Stack::allocate(100); //

pub fn push(&mut self, element: T)[src]

push the value on the top of stack.

Examples

extern crate drumatech;
use drumatech::structure;
let mut stack : structure::Stack<u8> = structure::Stack::allocate(100); //
stack.push(3);
assert_eq!(stack.contents[0],3);

pub fn pop(&mut self) -> Option<T>[src]

pop the value by the top of stack.

Examples

extern crate drumatech;
use drumatech::structure;
let mut stack : structure::Stack<u8> = structure::Stack::allocate(100); //
stack.push(3);
assert_eq!(stack.pop().unwrap(),3);

pub fn top(&self) -> Option<&T>[src]

get the value by the top of stack without changing contents.

Examples

extern crate drumatech;
use drumatech::structure;
let mut stack : structure::Stack<u8> = structure::Stack::allocate(100); //
stack.push(3);
assert_eq!(*stack.top().unwrap(),3);
assert_eq!(stack.pop().unwrap(),3);

impl<T: Clone> Stack<T>[src]

pub fn base(&self) -> T[src]

get the value by the base of stack without changing contents.

Examples

extern crate drumatech;
use drumatech::structure;
let mut stack : structure::Stack<u8> = structure::Stack::allocate(100); //
stack.push(3);
stack.push(2);
assert_eq!(stack.base(),3);
assert_eq!(stack.pop().unwrap(),2);

Trait Implementations

impl<T: Debug> Debug for Stack<T>[src]

Auto Trait Implementations

impl<T> Send for Stack<T> where
    T: Send

impl<T> Sync for Stack<T> where
    T: Sync

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]