Make all experimental storages optional
This commit is contained in:
parent
0a1d389bc7
commit
0b1499aa10
7 changed files with 81 additions and 14 deletions
|
|
@ -1,11 +1,55 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use librqbit::{
|
||||
storage::{examples::mmap::MmapStorageFactory, StorageFactoryExt},
|
||||
storage::{StorageFactory, StorageFactoryExt, TorrentStorage},
|
||||
SessionOptions,
|
||||
};
|
||||
use tracing::info;
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
struct CustomStorageFactory {
|
||||
_some_state_used_to_create_per_torrent_storage: (),
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
struct CustomStorage {
|
||||
_some_state_for_per_torrent_storage: (),
|
||||
}
|
||||
|
||||
impl StorageFactory for CustomStorageFactory {
|
||||
type Storage = CustomStorage;
|
||||
|
||||
fn init_storage(&self, _info: &librqbit::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
|
||||
Ok(CustomStorage::default())
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> librqbit::storage::BoxStorageFactory {
|
||||
self.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
impl TorrentStorage for CustomStorage {
|
||||
fn pread_exact(&self, _file_id: usize, _offset: u64, _buf: &mut [u8]) -> anyhow::Result<()> {
|
||||
anyhow::bail!("not implemented")
|
||||
}
|
||||
|
||||
fn pwrite_all(&self, _file_id: usize, _offset: u64, _buf: &[u8]) -> anyhow::Result<()> {
|
||||
anyhow::bail!("not implemented")
|
||||
}
|
||||
|
||||
fn remove_file(&self, _file_id: usize, _filename: &std::path::Path) -> anyhow::Result<()> {
|
||||
anyhow::bail!("not implemented")
|
||||
}
|
||||
|
||||
fn ensure_file_length(&self, _file_id: usize, _length: u64) -> anyhow::Result<()> {
|
||||
anyhow::bail!("not implemented")
|
||||
}
|
||||
|
||||
fn take(&self) -> anyhow::Result<Box<dyn TorrentStorage>> {
|
||||
anyhow::bail!("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
// Output logs to console.
|
||||
|
|
@ -31,7 +75,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
include_bytes!("../resources/ubuntu-21.04-live-server-amd64.iso.torrent").into(),
|
||||
),
|
||||
Some(librqbit::AddTorrentOptions {
|
||||
storage_factory: Some(MmapStorageFactory::default().boxed()),
|
||||
storage_factory: Some(CustomStorageFactory::default().boxed()),
|
||||
paused: false,
|
||||
..Default::default()
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue