pub fn dequeue(&mut self) -> Result<Option<T>, Box<dyn Error>> {
        if self.header.elements_count == 0 {
            return Ok(None);
        }
        let index = self.header.last_element;
        let bytes = self.store.read(index)?;
        let element: Element<T> = bincode::deserialize_from(bytes.as_slice())?;
        self.store.delete(index)?;
        self.header.last_element = element.prev;
        self.header.elements_count -= 1;
        self.save_header()?;
        Ok(Some(element.body))
    }
/// remove the item at the back of the queue, persist to disk and return the item
///
/// Note: if you discard the dequeued item it will be lost permanently!
///
/// # Examples
///
/// ```rust,no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// # let file = tempfile::tempfile()?;
/// let mut queue = wired::Queue::<String>::new(file)?;
/// queue.enqueue(String::from("some item"))?;
/// let item = queue.dequeue()?;
/// # Ok(())
/// # }
/// ```
remove the item at the back of the queue, persist to disk and return the item
Note: if you discard the dequeued item it will be lost permanently!
remove the item at the back of the queue persist to disk and return the item Note : if you discard the dequeued item it will be lost permanently!
pub fn dequeue(&mut self) -> Result<Option<T>, Box<dyn Error>> {
        if self.header.elements_count == 0 {
            return Ok(None);
        }
        let index = self.header.last_element;
        let bytes = self.store.read(index)?;
        let element: Element<T> = bincode::deserialize_from(bytes.as_slice())?;
        self.store.delete(index)?;
        self.header.last_element = element.prev;
        self.header.elements_count -= 1;
        self.save_header()?;
        Ok(Some(element.body))
    }
pub fn dequeue ( & mut self ) -> Result < Option < T > , Box < dyn Error > > { if self . header . elements_count == 0 { return Ok ( None ) ; } let index = self . header . last_element ; let bytes = self . store . read ( index ) ? ; let element : Element < T > = bincode :: deserialize_from ( bytes . as_slice ( ) ) ? ; self . store . delete ( index ) ? ; self . header . last_element = element . prev ; self . header . elements_count -= 1 ; self . save_header ( ) ? ; Ok ( Some ( element . body ) ) }
remove the item at the back of the queue, persist to disk and return the item
Note: if you discard the dequeued item it will be lost permanently!
remove the item at the back of the queue persist to disk and return the item Note : if you discard the dequeued item it will be lost permanently!
&mut self
&mut self
examples
None
fn main() -> result<(), box<dyn std::error::error>> {
None
let file = tempfile::tempfile()?;
let mut queue = wired::Queue::::new(file)?;
queue.enqueue(String::from("some item"))?;
let item = queue.dequeue()?.
let mut queue = wired :: Queue :::: new ( file ) ? ; queue . enqueue ( String :: from ( " some item " )) ? ; let item = queue . dequeue () ? .
ok(())
None
}
None