pub fn enqueue(&mut self, data: T) -> Result<(), Box<dyn Error>> {
        let mut element = Element {
            body: data,
            next: 0,
            prev: 0,
        };
        if self.header.first_element != 0 {
            element.next = self.header.first_element;
        }
        let bytes: Vec<u8> = bincode::serialize(&element)?;
        let index = self.store.create(bytes.as_slice())?;

        if self.header.first_element != 0 {
            let first_index = self.header.first_element;
            let first_bytes = self.store.read(first_index)?;
            let mut first: Element<T> = bincode::deserialize_from(first_bytes.as_slice())?;
            first.prev = index;
            let first_bytes: Vec<u8> = bincode::serialize(&first)?;
            self.store.update(first_index, first_bytes.as_slice())?;
        }
        if self.header.last_element == 0 {
            self.header.last_element = index;
        }
        self.header.first_element = index;
        self.header.elements_count += 1;
        self.save_header()?;
        Ok(())
    }
/// insert a new item in front of the queue and persist to disk
///
/// # Examples
///
/// ```rust,no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # let file = tempfile::tempfile()?;
/// let mut queue = wired::Queue::<String>::new(file)?;
/// let item = String::from("some item");
/// queue.enqueue(item)?;
/// # Ok(())
/// # }
/// ```
insert a new item in front of the queue and persist to disk
insert a new item in front of the queue and persist to disk
pub fn enqueue(&mut self, data: T) -> Result<(), Box<dyn Error>> {
        let mut element = Element {
            body: data,
            next: 0,
            prev: 0,
        };
        if self.header.first_element != 0 {
            element.next = self.header.first_element;
        }
        let bytes: Vec<u8> = bincode::serialize(&element)?;
        let index = self.store.create(bytes.as_slice())?;
        if self.header.first_element != 0 {
            let first_index = self.header.first_element;
            let first_bytes = self.store.read(first_index)?;
            let mut first: Element<T> = bincode::deserialize_from(first_bytes.as_slice())?;
            first.prev = index;
            let first_bytes: Vec<u8> = bincode::serialize(&first)?;
            self.store.update(first_index, first_bytes.as_slice())?;
        }
        if self.header.last_element == 0 {
            self.header.last_element = index;
        }
        self.header.first_element = index;
        self.header.elements_count += 1;
        self.save_header()?;
        Ok(())
    }
pub fn enqueue ( & mut self , data : T ) -> Result < ( ) , Box < dyn Error > > { let mut element = Element { body : data , next : 0 , prev : 0 , } ; if self . header . first_element != 0 { element . next = self . header . first_element ; } let bytes : Vec < u8 > = bincode :: serialize ( & element ) ? ; let index = self . store . create ( bytes . as_slice ( ) ) ? ; if self . header . first_element != 0 { let first_index = self . header . first_element ; let first_bytes = self . store . read ( first_index ) ? ; let mut first : Element < T > = bincode :: deserialize_from ( first_bytes . as_slice ( ) ) ? ; first . prev = index ; let first_bytes : Vec < u8 > = bincode :: serialize ( & first ) ? ; self . store . update ( first_index , first_bytes . as_slice ( ) ) ? ; } if self . header . last_element == 0 { self . header . last_element = index ; } self . header . first_element = index ; self . header . elements_count += 1 ; self . save_header ( ) ? ; Ok ( ( ) ) }
insert a new item in front of the queue and persist to disk
insert a new item in front of the queue 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 queue = wired::Queue::::new(file)?;
let item = String::from("some item");
queue.enqueue(item)?.
let mut queue = wired :: Queue :::: new ( file ) ? ; let item = String :: from ( " some item " ) ; queue . enqueue ( item ) ? .
ok(())
None
}
None