Trait PieceGetter

Source
pub trait PieceGetter: Debug {
    // Required methods
    fn get_piece<'life0, 'async_trait>(
        &'life0 self,
        piece_index: PieceIndex,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Piece>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_pieces<'a, 'async_trait>(
        &'a self,
        piece_indices: Vec<PieceIndex>,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = (PieceIndex, Result<Option<Piece>>)> + Send + Unpin + 'a>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait;

    // Provided method
    fn with_fallback<U>(self, other: U) -> FallbackPieceGetter<Self, U>
       where Self: Send + Sync + Sized,
             U: PieceGetter + Send + Sync { ... }
}
Expand description

Trait representing a way to get pieces

Required Methods§

Source

fn get_piece<'life0, 'async_trait>( &'life0 self, piece_index: PieceIndex, ) -> Pin<Box<dyn Future<Output = Result<Option<Piece>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get piece by index.

Returns Ok(None) if the piece is not found. Returns Err(_) if trying to get the piece caused an error.

Source

fn get_pieces<'a, 'async_trait>( &'a self, piece_indices: Vec<PieceIndex>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = (PieceIndex, Result<Option<Piece>>)> + Send + Unpin + 'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait,

Get pieces with provided indices.

The number of elements in the returned stream is the same as the number of unique piece_indices.

Provided Methods§

Source

fn with_fallback<U>(self, other: U) -> FallbackPieceGetter<Self, U>
where Self: Send + Sync + Sized, U: PieceGetter + Send + Sync,

Returns a piece getter that falls back to other if self does not return the piece. Piece getters may need to be wrapped in Arc to be used with this method.

Implementations on Foreign Types§

Source§

impl PieceGetter for (PieceIndex, Piece)

Source§

fn get_piece<'life0, 'async_trait>( &'life0 self, piece_index: PieceIndex, ) -> Pin<Box<dyn Future<Output = Result<Option<Piece>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_pieces<'a, 'async_trait>( &'a self, piece_indices: Vec<PieceIndex>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = (PieceIndex, Result<Option<Piece>>)> + Send + Unpin + 'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait,

Source§

impl PieceGetter for Vec<(PieceIndex, Piece)>

Source§

fn get_piece<'life0, 'async_trait>( &'life0 self, piece_index: PieceIndex, ) -> Pin<Box<dyn Future<Output = Result<Option<Piece>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_pieces<'a, 'async_trait>( &'a self, piece_indices: Vec<PieceIndex>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = (PieceIndex, Result<Option<Piece>>)> + Send + Unpin + 'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait,

Source§

impl PieceGetter for NewArchivedSegment

Source§

fn get_piece<'life0, 'async_trait>( &'life0 self, piece_index: PieceIndex, ) -> Pin<Box<dyn Future<Output = Result<Option<Piece>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_pieces<'a, 'async_trait>( &'a self, piece_indices: Vec<PieceIndex>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = (PieceIndex, Result<Option<Piece>>)> + Send + Unpin + 'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait,

Source§

impl<T> PieceGetter for Option<T>
where T: PieceGetter + Send + Sync,

Source§

fn get_piece<'life0, 'async_trait>( &'life0 self, piece_index: PieceIndex, ) -> Pin<Box<dyn Future<Output = Result<Option<Piece>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_pieces<'a, 'async_trait>( &'a self, piece_indices: Vec<PieceIndex>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = (PieceIndex, Result<Option<Piece>>)> + Send + Unpin + 'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait,

Source§

impl<T> PieceGetter for Box<T>
where T: PieceGetter + Send + Sync + ?Sized,

Source§

fn get_piece<'life0, 'async_trait>( &'life0 self, piece_index: PieceIndex, ) -> Pin<Box<dyn Future<Output = Result<Option<Piece>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_pieces<'a, 'async_trait>( &'a self, piece_indices: Vec<PieceIndex>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = (PieceIndex, Result<Option<Piece>>)> + Send + Unpin + 'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait,

Source§

impl<T> PieceGetter for Arc<T>
where T: PieceGetter + Send + Sync + ?Sized,

Source§

fn get_piece<'life0, 'async_trait>( &'life0 self, piece_index: PieceIndex, ) -> Pin<Box<dyn Future<Output = Result<Option<Piece>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_pieces<'a, 'async_trait>( &'a self, piece_indices: Vec<PieceIndex>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = (PieceIndex, Result<Option<Piece>>)> + Send + Unpin + 'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait,

Implementors§