Mirror

Struct Mirror 

Source
pub struct Mirror<'a> { /* private fields */ }
Expand description

Struct representing a mirror for mirroring operations across multiple stores.

Implementations§

Source§

impl<'a> Mirror<'a>

Source

pub async fn write<C>(&self, path: &Path, content: C) -> MirrorResult<()>
where C: AsRef<[u8]> + Send,

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

Source

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

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.