Skip to main content

Bite

Struct Bite 

Source
pub struct Bite<'a, T> { /* private fields */ }
Expand description

A borrowed, transactional prefix of a BiteQueue.

The source queue stays exclusively borrowed until this value is committed, explicitly rolled back, or dropped.

Implementations§

Source§

impl<T> Bite<'_, T>

Source

pub fn len(&self) -> usize

Number of items in this bite.

Source

pub fn is_empty(&self) -> bool

Returns whether this bite contains no items.

A bite from an empty queue can be empty even though its requested maximum was non-zero.

Source

pub fn front(&self) -> Option<&T>

First item in this bite.

Examples found in repository?
examples/worker.rs (line 11)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let mut queue = BiteQueue::from_iter(["task-1", "task-2", "task-3"]);
5
6    let completed = queue.bite(2)?.commit();
7    println!("completed: {completed:?}");
8
9    {
10        let retry = queue.bite(1)?;
11        println!("will retry: {:?}", retry.front());
12    }
13
14    println!("remaining: {:?}", queue.iter().collect::<Vec<_>>());
15    Ok(())
16}
Source

pub fn iter(&self) -> impl ExactSizeIterator<Item = &T> + DoubleEndedIterator

Iterates over the bite in original FIFO order.

Source

pub fn commit(self) -> Vec<T>

Commits the bite and returns its items in FIFO order.

Examples found in repository?
examples/worker.rs (line 6)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let mut queue = BiteQueue::from_iter(["task-1", "task-2", "task-3"]);
5
6    let completed = queue.bite(2)?.commit();
7    println!("completed: {completed:?}");
8
9    {
10        let retry = queue.bite(1)?;
11        println!("will retry: {:?}", retry.front());
12    }
13
14    println!("remaining: {:?}", queue.iter().collect::<Vec<_>>());
15    Ok(())
16}
Source

pub fn rollback(self)

Explicitly restores the bite to the queue.

Dropping without calling either commit or rollback has the same restoration behavior.

Trait Implementations§

Source§

impl<T: Debug> Debug for Bite<'_, T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for Bite<'_, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'a, T> IntoIterator for &'a Bite<'_, T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a, T> !UnwindSafe for Bite<'a, T>

§

impl<'a, T> Freeze for Bite<'a, T>
where &'a mut BiteQueue<T>: Freeze, VecDeque<T>: Freeze,

§

impl<'a, T> RefUnwindSafe for Bite<'a, T>

§

impl<'a, T> Send for Bite<'a, T>
where &'a mut BiteQueue<T>: Send, VecDeque<T>: Send,

§

impl<'a, T> Sync for Bite<'a, T>
where &'a mut BiteQueue<T>: Sync, VecDeque<T>: Sync,

§

impl<'a, T> Unpin for Bite<'a, T>
where &'a mut BiteQueue<T>: Unpin, VecDeque<T>: Unpin,

§

impl<'a, T> UnsafeUnpin for Bite<'a, T>
where &'a mut BiteQueue<T>: UnsafeUnpin, VecDeque<T>: UnsafeUnpin,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.