fix: fixes according to PR comments

- Reset previous implementation of InMemoryExampleStorage
- Implement default (empty) behaviour of on_piece_completed in trait
  itself
- Now passing a ValidPieceIndex in on_piece_completed
This commit is contained in:
LIAUD Corentin 2024-08-28 08:26:06 +02:00
parent 35d57ae8a2
commit 9183df0ebd
No known key found for this signature in database
GPG key ID: 48D3490FB1A44E6A
6 changed files with 19 additions and 79 deletions

View file

@ -11,6 +11,8 @@ use std::{
path::Path,
};
use librqbit_core::lengths::ValidPieceIndex;
use crate::torrent_state::ManagedTorrentShared;
pub trait StorageFactory: Send + Sync + Any {
@ -99,7 +101,10 @@ pub trait TorrentStorage: Send + Sync {
fn take(&self) -> anyhow::Result<Box<dyn TorrentStorage>>;
/// Callback called every time a piece has completed and has been validated.
fn on_piece_completed(&self, file_id: usize, offset: u64) -> anyhow::Result<()>;
/// Default implementation does nothing, but can be override in trait implementations.
fn on_piece_completed(&self, _piece_index: ValidPieceIndex) -> anyhow::Result<()> {
Ok(())
}
}
impl<U: TorrentStorage + ?Sized> TorrentStorage for Box<U> {
@ -131,7 +136,7 @@ impl<U: TorrentStorage + ?Sized> TorrentStorage for Box<U> {
(**self).init(meta)
}
fn on_piece_completed(&self, file_id: usize, offset: u64) -> anyhow::Result<()> {
(**self).on_piece_completed(file_id, offset)
fn on_piece_completed(&self, piece_id: ValidPieceIndex) -> anyhow::Result<()> {
(**self).on_piece_completed(piece_id)
}
}