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

@ -2,8 +2,9 @@ use std::time::Duration;
use rand_distr::Distribution;
use crate::storage::{StorageFactory, TorrentStorage};
use crate::storage::{StorageFactory, StorageFactoryExt, TorrentStorage};
#[derive(Clone)]
pub struct SlowStorageFactory<U> {
underlying_factory: U,
}
@ -16,7 +17,7 @@ impl<U: StorageFactory> SlowStorageFactory<U> {
}
}
impl<U: StorageFactory> StorageFactory for SlowStorageFactory<U> {
impl<U: StorageFactory + Clone> StorageFactory for SlowStorageFactory<U> {
type Storage = SlowStorage<U::Storage>;
fn init_storage(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
@ -28,6 +29,10 @@ impl<U: StorageFactory> StorageFactory for SlowStorageFactory<U> {
fn is_type_id(&self, type_id: std::any::TypeId) -> bool {
self.underlying_factory.is_type_id(type_id)
}
fn clone_box(&self) -> crate::storage::BoxStorageFactory {
self.clone().boxed()
}
}
pub struct SlowStorage<U> {

View file

@ -1,5 +1,6 @@
use crate::storage::{StorageFactory, TorrentStorage};
use crate::storage::{StorageFactory, StorageFactoryExt, TorrentStorage};
#[derive(Clone)]
pub struct TimingStorageFactory<U> {
name: String,
underlying_factory: U,
@ -14,7 +15,7 @@ impl<U> TimingStorageFactory<U> {
}
}
impl<U: StorageFactory> StorageFactory for TimingStorageFactory<U> {
impl<U: StorageFactory + Clone> StorageFactory for TimingStorageFactory<U> {
type Storage = TimingStorage<U::Storage>;
fn init_storage(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
@ -27,6 +28,10 @@ impl<U: StorageFactory> StorageFactory for TimingStorageFactory<U> {
fn is_type_id(&self, type_id: std::any::TypeId) -> bool {
self.underlying_factory.is_type_id(type_id)
}
fn clone_box(&self) -> crate::storage::BoxStorageFactory {
self.clone().boxed()
}
}
pub struct TimingStorage<U> {