pub fn push(&mut self, data: T) -> Result<(), Box<dyn Error>> {
        let mut element = Element {
            body: data,
            prev: 0,
        };
        if self.header.last_element != 0 {
            element.prev = self.header.last_element;
        }
        let bytes: Vec<u8> = bincode::serialize(&element)?;
        let index = self.store.create(bytes.as_slice())?;
        self.header.last_element = index;
        self.header.elements_count += 1;
        self.save_header()?;
        Ok(())
    }
/// insert a new item at the end of the stack and persist to disk
///
/// # Examples
///
/// ```rust,no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # let file = tempfile::tempfile()?;
/// let mut stack = wired::Stack::<String>::new(file)?;
/// let item = String::from("some item");
/// stack.push(item)?;
/// # Ok(())
/// # }
/// ```
insert a new item at the end of the stack and persist to disk
insert a new item at the end of the stack and persist to disk
pub fn push(&mut self, data: T) -> Result<(), Box<dyn Error>> {
        let mut element = Element {
            body: data,
            prev: 0,
        };
        if self.header.last_element != 0 {
            element.prev = self.header.last_element;
        }
        let bytes: Vec<u8> = bincode::serialize(&element)?;
        let index = self.store.create(bytes.as_slice())?;
        self.header.last_element = index;
        self.header.elements_count += 1;
        self.save_header()?;
        Ok(())
    }
pub fn push ( & mut self , data : T ) -> Result < ( ) , Box < dyn Error > > { let mut element = Element { body : data , prev : 0 , } ; if self . header . last_element != 0 { element . prev = self . header . last_element ; } let bytes : Vec < u8 > = bincode :: serialize ( & element ) ? ; let index = self . store . create ( bytes . as_slice ( ) ) ? ; self . header . last_element = index ; self . header . elements_count += 1 ; self . save_header ( ) ? ; Ok ( ( ) ) }
insert a new item at the end of the stack and persist to disk
insert a new item at the end of the stack and persist to disk
&mut self
data
T
&mut self
data
T
examples
None
fn main() -> result<(), box<dyn std::error::error>> {
None
let file = tempfile::tempfile()?;
let mut stack = wired::Stack::::new(file)?;
let item = String::from("some item");
stack.push(item)?.
let mut stack = wired :: Stack :::: new ( file ) ? ; let item = String :: from ( " some item " ) ; stack . push ( item ) ? .
ok(())
None
}
None