pub trait TicketQueue {
type Error: Error + Send + Sync + 'static;
// Required methods
fn len(&self) -> Result<usize, Self::Error>;
fn push(&mut self, ticket: RedeemableTicket) -> Result<(), Self::Error>;
fn pop(&mut self) -> Result<Option<RedeemableTicket>, Self::Error>;
fn peek(&self) -> Result<Option<RedeemableTicket>, Self::Error>;
fn iter_unordered(
&self,
) -> Result<impl Iterator<Item = Result<RedeemableTicket, Self::Error>>, Self::Error>;
// Provided methods
fn is_empty(&self) -> Result<bool, Self::Error> { ... }
fn total_value(
&self,
epoch: u32,
min_index: Option<u64>,
) -> Result<HoprBalance, Self::Error> { ... }
fn drain(&mut self) -> Result<Vec<VerifiedTicket>, Self::Error> { ... }
}Expand description
Backend for the incoming ticket storage (double-ended) queue.
This trait defines the operations that an incoming ticket queue for a specific channel must support. A queue can only store redeemable tickets from the same channel but can contain tickets from different channel epochs.
The implementations must honor the natural ordering of tickets.
Required Associated Types§
Required Methods§
Sourcefn push(&mut self, ticket: RedeemableTicket) -> Result<(), Self::Error>
fn push(&mut self, ticket: RedeemableTicket) -> Result<(), Self::Error>
Add a ticket to the queue.
Sourcefn pop(&mut self) -> Result<Option<RedeemableTicket>, Self::Error>
fn pop(&mut self) -> Result<Option<RedeemableTicket>, Self::Error>
Remove and return the next ticket in-order from the queue.
This extracts the next ticket from the queue (after redeeming or neglecting it).
Sourcefn peek(&self) -> Result<Option<RedeemableTicket>, Self::Error>
fn peek(&self) -> Result<Option<RedeemableTicket>, Self::Error>
Return the next ticket in-order from the queue without removing it.
This is the next ticket that can be extracted from the queue (redeemed or neglected).
Sourcefn iter_unordered(
&self,
) -> Result<impl Iterator<Item = Result<RedeemableTicket, Self::Error>>, Self::Error>
fn iter_unordered( &self, ) -> Result<impl Iterator<Item = Result<RedeemableTicket, Self::Error>>, Self::Error>
Iterate over all tickets in the queue in arbitrary order.
This is not the order in which tickets are redeemed or neglected (see TicketQueue::pop or
TicketQueue::peek).
Provided Methods§
Sourcefn total_value(
&self,
epoch: u32,
min_index: Option<u64>,
) -> Result<HoprBalance, Self::Error>
fn total_value( &self, epoch: u32, min_index: Option<u64>, ) -> Result<HoprBalance, Self::Error>
Computes the total value of tickets of the given epoch (and optionally minimum given index) in this queue.
The default implementation simply iterates the queue and sums the total value of matching tickets. Implementations can provide more effective methods.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.