pub trait PieceCache:
Send
+ Sync
+ Debug {
// Required methods
fn id(&self) -> &PieceCacheId;
fn max_num_elements(&self) -> u32;
fn contents<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<(PieceCacheOffset, Option<PieceIndex>), FarmError>> + Unpin + Send + '_>, FarmError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn write_piece<'life0, 'life1, 'async_trait>(
&'life0 self,
offset: PieceCacheOffset,
piece_index: PieceIndex,
piece: &'life1 Piece,
) -> Pin<Box<dyn Future<Output = Result<(), FarmError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn read_piece_index<'life0, 'async_trait>(
&'life0 self,
offset: PieceCacheOffset,
) -> Pin<Box<dyn Future<Output = Result<Option<PieceIndex>, FarmError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn read_piece<'life0, 'async_trait>(
&'life0 self,
offset: PieceCacheOffset,
) -> Pin<Box<dyn Future<Output = Result<Option<(PieceIndex, Piece)>, FarmError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn read_pieces<'life0, 'async_trait>(
&'life0 self,
offsets: Box<dyn Iterator<Item = PieceCacheOffset> + Send>,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<(PieceCacheOffset, Option<(PieceIndex, Piece)>), FarmError>> + Send + Unpin + '_>, FarmError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
Abstract piece cache implementation.
Piece cache is a simple container that stores concatenated pieces in a flat file at specific offsets. Implementation doesn’t have to be local though, cache can be remote somewhere on the network, APIs are intentionally async to account for that.
Required Methods§
sourcefn id(&self) -> &PieceCacheId
fn id(&self) -> &PieceCacheId
ID of this cache
sourcefn max_num_elements(&self) -> u32
fn max_num_elements(&self) -> u32
Max number of elements in this cache
sourcefn contents<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<(PieceCacheOffset, Option<PieceIndex>), FarmError>> + Unpin + Send + '_>, FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn contents<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<(PieceCacheOffset, Option<PieceIndex>), FarmError>> + Unpin + Send + '_>, FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Contents of this piece cache.
NOTE: it is possible to do concurrent reads and writes, higher level logic must ensure this doesn’t happen for the same piece being accessed!
sourcefn write_piece<'life0, 'life1, 'async_trait>(
&'life0 self,
offset: PieceCacheOffset,
piece_index: PieceIndex,
piece: &'life1 Piece,
) -> Pin<Box<dyn Future<Output = Result<(), FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn write_piece<'life0, 'life1, 'async_trait>(
&'life0 self,
offset: PieceCacheOffset,
piece_index: PieceIndex,
piece: &'life1 Piece,
) -> Pin<Box<dyn Future<Output = Result<(), FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Store piece in cache at specified offset, replacing existing piece if there is any.
NOTE: it is possible to do concurrent reads and writes, higher level logic must ensure this doesn’t happen for the same piece being accessed!
sourcefn read_piece_index<'life0, 'async_trait>(
&'life0 self,
offset: PieceCacheOffset,
) -> Pin<Box<dyn Future<Output = Result<Option<PieceIndex>, FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn read_piece_index<'life0, 'async_trait>(
&'life0 self,
offset: PieceCacheOffset,
) -> Pin<Box<dyn Future<Output = Result<Option<PieceIndex>, FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Read piece index from cache at specified offset.
Returns None
if offset is out of range.
NOTE: it is possible to do concurrent reads and writes, higher level logic must ensure this doesn’t happen for the same piece being accessed!
sourcefn read_piece<'life0, 'async_trait>(
&'life0 self,
offset: PieceCacheOffset,
) -> Pin<Box<dyn Future<Output = Result<Option<(PieceIndex, Piece)>, FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn read_piece<'life0, 'async_trait>(
&'life0 self,
offset: PieceCacheOffset,
) -> Pin<Box<dyn Future<Output = Result<Option<(PieceIndex, Piece)>, FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Read piece from cache at specified offset.
Returns None
if offset is out of range.
NOTE: it is possible to do concurrent reads and writes, higher level logic must ensure this doesn’t happen for the same piece being accessed!
sourcefn read_pieces<'life0, 'async_trait>(
&'life0 self,
offsets: Box<dyn Iterator<Item = PieceCacheOffset> + Send>,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<(PieceCacheOffset, Option<(PieceIndex, Piece)>), FarmError>> + Send + Unpin + '_>, FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn read_pieces<'life0, 'async_trait>(
&'life0 self,
offsets: Box<dyn Iterator<Item = PieceCacheOffset> + Send>,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<(PieceCacheOffset, Option<(PieceIndex, Piece)>), FarmError>> + Send + Unpin + '_>, FarmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Read pieces from cache at specified offsets.
Number of elements in returned stream is the same as number of unique offsets
.
Returns None
for offsets that are out of range.
NOTE: it is possible to do concurrent reads and writes, higher level logic must ensure this doesn’t happen for the same pieces being accessed!