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>
impl<T> Bite<'_, T>
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn front(&self) -> Option<&T>
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}Sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = &T> + DoubleEndedIterator
pub fn iter(&self) -> impl ExactSizeIterator<Item = &T> + DoubleEndedIterator
Iterates over the bite in original FIFO order.
Sourcepub fn commit(self) -> Vec<T>
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}Trait Implementations§
Auto Trait Implementations§
impl<'a, T> !UnwindSafe for Bite<'a, T>
impl<'a, T> Freeze for Bite<'a, T>
impl<'a, T> RefUnwindSafe for Bite<'a, T>
impl<'a, T> Send for Bite<'a, T>
impl<'a, T> Sync for Bite<'a, T>
impl<'a, T> Unpin for Bite<'a, T>
impl<'a, T> UnsafeUnpin for Bite<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more