Skip to main content

TicketQueue

Trait TicketQueue 

Source
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§

Source

type Error: Error + Send + Sync + 'static

Required Methods§

Source

fn len(&self) -> Result<usize, Self::Error>

Number of tickets in the queue.

Source

fn push(&mut self, ticket: RedeemableTicket) -> Result<(), Self::Error>

Add a ticket to the queue.

Source

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).

Source

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).

Source

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§

Source

fn is_empty(&self) -> Result<bool, Self::Error>

Indicates whether the queue is empty.

Source

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.

Source

fn drain(&mut self) -> Result<Vec<VerifiedTicket>, Self::Error>

Drains all the remaining tickets from the queue, rendering them no longer redeemable.

The drained tickets are still ordered according to their natural ordering.

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.

Implementors§