Struct Queue

Source
pub struct Queue<T> { /* private fields */ }
Expand description

A durable queue backed by the filesystem.

This queue stores items of type T as files in a spool directory. Files are serialized with serde_json so T must derive serde’s Serialize and Deserialize traits.

The queue’s directory should only contain items of the same type. Any files in the spool that fail to deserialize will be discarded.

Implementations§

Source§

impl<T: Serialize + Deserialize> Queue<T>

Source

pub fn new(path: &str) -> Result<Queue<T>, Error>

Create a new Queue<T> using the given directory path for storage.

Source

pub fn push(&mut self, item: T) -> Result<(), Error>

Push an item into the Queue.

Source

pub fn pop(&self) -> Result<Option<T>, Error>

Pop an item off the queue.

This method returns the first matching directory entry. Queue ordering cannot be guaranteed to be consistent across all operating systems and filesystems, as the serialized file will be chosen based on the filesystem’s directory entry ordering.

Popped items are not removed from the filesystem immediately; instead, they are marked for deletion. Use flush() to cause the items to be permanently removed from the underlying filesystem.

Source

pub fn pop_filter<F>(&self, filter: F) -> Result<Option<T>, Error>
where F: Fn(&T) -> bool,

Pop an item off the queue matching the filter function.

This method works the same as pop(), except the item must match the given function or it is not popped off the queue.

Source

pub fn drain(&self) -> Result<Vec<T>, Error>

Source

pub fn flush(&self) -> Result<(), Error>

Flush removes all pending item files marked for deletion.

Source

pub fn recover(&self) -> Result<(), Error>

Recover unmarks all pending item files that were previously marked for deletion.

Use recover to ensure that popped items are processed at least once, when it is uncertain whether they were processed due to a crash.

This method is only recommended if items are being processed idempotently.

Trait Implementations§

Source§

impl<T: Clone> Clone for Queue<T>

Source§

fn clone(&self) -> Queue<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Queue<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Queue<T>

§

impl<T> RefUnwindSafe for Queue<T>
where T: RefUnwindSafe,

§

impl<T> Send for Queue<T>
where T: Send,

§

impl<T> Sync for Queue<T>
where T: Sync,

§

impl<T> Unpin for Queue<T>
where T: Unpin,

§

impl<T> UnwindSafe for Queue<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.