Clone storage factories...

This commit is contained in:
Igor Katson 2024-05-02 20:16:14 +01:00
parent 07a5b69a25
commit 427f490a61
10 changed files with 62 additions and 21 deletions

View file

@ -6,7 +6,7 @@ use parking_lot::RwLock;
use crate::type_aliases::FileInfos;
use crate::storage::{StorageFactory, TorrentStorage};
use crate::storage::{StorageFactory, StorageFactoryExt, TorrentStorage};
struct InMemoryPiece {
bytes: Box<[u8]>,
@ -19,7 +19,7 @@ impl InMemoryPiece {
}
}
#[derive(Default)]
#[derive(Default, Clone)]
pub struct InMemoryExampleStorageFactory {}
impl StorageFactory for InMemoryExampleStorageFactory {
@ -31,6 +31,10 @@ impl StorageFactory for InMemoryExampleStorageFactory {
) -> anyhow::Result<InMemoryExampleStorage> {
InMemoryExampleStorage::new(info.lengths, info.file_infos.clone())
}
fn clone_box(&self) -> crate::storage::BoxStorageFactory {
self.clone().boxed()
}
}
pub struct InMemoryExampleStorage {

View file

@ -3,11 +3,11 @@ use memmap2::{MmapMut, MmapOptions};
use parking_lot::RwLock;
use crate::{
storage::{StorageFactory, TorrentStorage},
storage::{StorageFactory, StorageFactoryExt, TorrentStorage},
FileInfos, ManagedTorrentInfo,
};
#[derive(Default)]
#[derive(Default, Clone)]
pub struct MmapStorageFactory {}
pub struct MmapStorage {
@ -28,6 +28,10 @@ impl StorageFactory for MmapStorageFactory {
file_infos: info.file_infos.clone(),
})
}
fn clone_box(&self) -> crate::storage::BoxStorageFactory {
self.clone().boxed()
}
}
impl TorrentStorage for MmapStorage {