pub struct Mirror<'a> { /* private fields */ }Expand description
Struct representing a mirror for mirroring operations across multiple stores.
Implementations§
Source§impl<'a> Mirror<'a>
impl<'a> Mirror<'a>
Sourcepub async fn write<C>(&self, path: &Path, content: C) -> MirrorResult<()>
pub async fn write<C>(&self, path: &Path, content: C) -> MirrorResult<()>
Writes content to all stores in the mirror.
§Example
use std::{collections::HashMap, path::PathBuf};
use active_storage::{drivers, multi_store::MultiStore, StoreConfig};
#[tokio::main]
async fn main() {
let config = drivers::disk::Config {
location: PathBuf::from("tmp").join("primary-storage"),
};
let disk_driver = StoreConfig::Disk(config).build().await.unwrap();
let inmem_driver = StoreConfig::InMem().build().await.unwrap();
let mut multi_store = MultiStore::new(disk_driver);
multi_store.add_stores(HashMap::from([("secondary", inmem_driver)]));
let _ = multi_store
.mirror_stores_from_primary()
.write(PathBuf::from("test").as_path(), b"content")
.await;
} §Errors
Depend of the mirror policy return operation failure
Sourcepub async fn delete(&self, path: &Path) -> MirrorResult<()>
pub async fn delete(&self, path: &Path) -> MirrorResult<()>
Deletes a file from all stores in the mirror.
§Example
use std::{collections::HashMap, path::PathBuf};
use active_storage::{drivers, multi_store::MultiStore, StoreConfig};
#[tokio::main]
async fn main() {
let config = drivers::disk::Config {
location: PathBuf::from("tmp").join("store-1"),
};
let disk_driver = StoreConfig::Disk(config).build().await.unwrap();
let inmem_driver = StoreConfig::InMem().build().await.unwrap();
let mut multi_store = MultiStore::new(disk_driver);
multi_store.add_stores(HashMap::from([("secondary", inmem_driver)]));
let _ = multi_store
.mirror_stores_from_primary()
.write(PathBuf::from("test").as_path(), b"content")
.await;
let _ = multi_store
.mirror_stores_from_primary()
.delete(PathBuf::from("test").as_path())
.await;
} §Errors
Depend of the mirror policy return operation failure
Sourcepub async fn delete_directory(&self, path: &Path) -> MirrorResult<()>
pub async fn delete_directory(&self, path: &Path) -> MirrorResult<()>
Deletes a directory from all stores in the mirror.
§Example
use std::{collections::HashMap, path::PathBuf};
use active_storage::{drivers, multi_store::MultiStore, StoreConfig};
#[tokio::main]
async fn main() {
let config = drivers::disk::Config {
location: PathBuf::from("tmp").join("primary-storage"),
};
let disk_driver = StoreConfig::Disk(config).build().await.unwrap();
let inmem_driver = StoreConfig::InMem().build().await.unwrap();
let mut multi_store = MultiStore::new(disk_driver);
multi_store.add_stores(HashMap::from([("secondary", inmem_driver)]));
let _ = multi_store
.mirror_stores_from_primary()
.write(PathBuf::from("folder").join("file").as_path(), b"content")
.await;
let _ = multi_store
.mirror_stores_from_primary()
.delete_directory(PathBuf::from("folder").as_path())
.await;
} §Errors
Returns an error if any store fails to delete the directory.
Auto Trait Implementations§
impl<'a> Freeze for Mirror<'a>
impl<'a> !RefUnwindSafe for Mirror<'a>
impl<'a> Send for Mirror<'a>
impl<'a> Sync for Mirror<'a>
impl<'a> Unpin for Mirror<'a>
impl<'a> !UnwindSafe for Mirror<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more