storages generics
This commit is contained in:
parent
fdc9243a41
commit
e4adfa569a
3 changed files with 46 additions and 18 deletions
|
|
@ -12,6 +12,12 @@ pub trait StorageFactory: Send + Sync + Any {
|
|||
fn init_storage(&self, info: &ManagedTorrentInfo) -> anyhow::Result<Box<dyn TorrentStorage>>;
|
||||
}
|
||||
|
||||
impl<U: StorageFactory + ?Sized> StorageFactory for Box<U> {
|
||||
fn init_storage(&self, info: &ManagedTorrentInfo) -> anyhow::Result<Box<dyn TorrentStorage>> {
|
||||
(**self).init_storage(info)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TorrentStorage: Send + Sync {
|
||||
fn pread_exact(&self, file_id: usize, offset: u64, buf: &mut [u8]) -> anyhow::Result<()>;
|
||||
|
||||
|
|
@ -23,3 +29,25 @@ pub trait TorrentStorage: Send + Sync {
|
|||
|
||||
fn take(&self) -> anyhow::Result<Box<dyn TorrentStorage>>;
|
||||
}
|
||||
|
||||
impl<U: TorrentStorage + ?Sized> TorrentStorage for Box<U> {
|
||||
fn pread_exact(&self, file_id: usize, offset: u64, buf: &mut [u8]) -> anyhow::Result<()> {
|
||||
(**self).pread_exact(file_id, offset, buf)
|
||||
}
|
||||
|
||||
fn pwrite_all(&self, file_id: usize, offset: u64, buf: &[u8]) -> anyhow::Result<()> {
|
||||
(**self).pwrite_all(file_id, offset, buf)
|
||||
}
|
||||
|
||||
fn remove_file(&self, file_id: usize, filename: &Path) -> anyhow::Result<()> {
|
||||
(**self).remove_file(file_id, filename)
|
||||
}
|
||||
|
||||
fn ensure_file_length(&self, file_id: usize, length: u64) -> anyhow::Result<()> {
|
||||
(**self).ensure_file_length(file_id, length)
|
||||
}
|
||||
|
||||
fn take(&self) -> anyhow::Result<Box<dyn TorrentStorage>> {
|
||||
(**self).take()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue