rqbit/crates/librqbit/src/bitv_factory.rs

34 lines
914 B
Rust
Raw Normal View History

2024-08-20 20:42:24 +01:00
use crate::{api::TorrentIdOrHash, bitv::BitV, type_aliases::BF};
2024-08-20 16:51:34 +01:00
#[async_trait::async_trait]
2024-08-20 20:42:24 +01:00
pub trait BitVFactory: Send + Sync {
2024-08-20 16:51:34 +01:00
async fn load(&self, id: TorrentIdOrHash) -> anyhow::Result<Option<Box<dyn BitV>>>;
2024-08-21 18:21:15 +01:00
async fn clear(&self, id: TorrentIdOrHash) -> anyhow::Result<()>;
2024-08-20 16:51:34 +01:00
async fn store_initial_check(
&self,
id: TorrentIdOrHash,
2024-08-20 20:42:24 +01:00
b: BF,
2024-08-20 16:51:34 +01:00
) -> anyhow::Result<Box<dyn BitV>>;
}
pub struct NonPersistentBitVFactory {}
#[async_trait::async_trait]
impl BitVFactory for NonPersistentBitVFactory {
async fn load(&self, _: TorrentIdOrHash) -> anyhow::Result<Option<Box<dyn BitV>>> {
Ok(None)
}
2024-08-20 21:31:52 +01:00
2024-08-21 18:21:15 +01:00
async fn clear(&self, _id: TorrentIdOrHash) -> anyhow::Result<()> {
Ok(())
}
2024-08-20 16:51:34 +01:00
async fn store_initial_check(
&self,
2024-08-20 20:42:24 +01:00
_id: TorrentIdOrHash,
b: BF,
2024-08-20 16:51:34 +01:00
) -> anyhow::Result<Box<dyn BitV>> {
Ok(Box::new(b))
}
}