pub struct Store { /* private fields */ }Implementations§
Source§impl Store
impl Store
pub fn new(driver: Box<dyn Driver>) -> Self
Sourcepub async fn file_exists(&self, path: &Path) -> DriverResult<bool>
pub async fn file_exists(&self, path: &Path) -> DriverResult<bool>
Checks if a file exists at the specified path within the storage.
§Parameters
path: The path to the file to be checked.
§Examples
use std::path::PathBuf;
use active_storage::StoreConfig;
#[tokio::main]
async fn main() {
let inmem_driver = StoreConfig::InMem().build().await.unwrap();
let file_path = PathBuf::from("test.txt");
inmem_driver.write(file_path.as_path(), "my content").await;
assert!(inmem_driver.file_exists(file_path.as_path()).await.unwrap());
}§Errors
Returns an error if the underlying Driver encounters an issue while
checking file existence.
Sourcepub async fn write<C: AsRef<[u8]> + Send>(
&self,
path: &Path,
content: C,
) -> DriverResult<()>
pub async fn write<C: AsRef<[u8]> + Send>( &self, path: &Path, content: C, ) -> DriverResult<()>
Writes the provided contents to a file at the specified path within the storage.
§Parameters
path: The path to the file to be written.contents: The contents to be written to the file.
§Examples
use std::path::PathBuf;
use active_storage::StoreConfig;
#[tokio::main]
async fn main() {
let inmem_driver = StoreConfig::InMem().build().await.unwrap();
let file_path = PathBuf::from("test.txt");
assert!(inmem_driver.write(file_path.as_path(), "my content").await.is_ok());
}§Errors
Returns an error if the underlying Driver encounters an issue while
writing to the file.
Sourcepub async fn read<T: TryFrom<Contents>>(&self, path: &Path) -> DriverResult<T>
pub async fn read<T: TryFrom<Contents>>(&self, path: &Path) -> DriverResult<T>
Reads the contents of a file at the specified path within the storage.
§Parameters
path: The path to the file to be read.
§Examples
use std::path::PathBuf;
use active_storage::StoreConfig;
#[tokio::main]
async fn main() {
let inmem_driver = StoreConfig::InMem().build().await.unwrap();
let file_path = PathBuf::from("test.txt");
inmem_driver.write(file_path.as_path(), "my content").await;
assert_eq!(
inmem_driver.read::<String>(file_path.as_path()).await.unwrap(),
"my content".to_string(),
);
}§Errors
Returns an error if the underlying Driver encounters an issue while
reading from the file.
Sourcepub async fn delete(&self, path: &Path) -> DriverResult<()>
pub async fn delete(&self, path: &Path) -> DriverResult<()>
Deletes a file at the specified path within the storage.
§Parameters
path: The path to the file to be deleted.
§Examples
use std::path::PathBuf;
use active_storage::StoreConfig;
#[tokio::main]
async fn main() {
let inmem_driver = StoreConfig::InMem().build().await.unwrap();
let file_path = PathBuf::from("test.txt");
inmem_driver.write(file_path.as_path(), "my content").await;
assert!(inmem_driver.delete(file_path.as_path()).await.is_ok());
}§Errors
Returns an error if the underlying Driver encounters an issue while
deleting the file.
Sourcepub async fn delete_directory(&self, path: &Path) -> DriverResult<()>
pub async fn delete_directory(&self, path: &Path) -> DriverResult<()>
Deletes a directory at the specified path within the storage.
§Parameters
path: The path to the directory to be deleted.
§Examples
use std::path::PathBuf;
use active_storage::StoreConfig;
#[tokio::main]
async fn main() {
let inmem_driver = StoreConfig::InMem().build().await.unwrap();
let folder = PathBuf::from("foo");
let file_path = folder.join("bar.txt");
inmem_driver.write(file_path.as_path(), "my content").await;
assert!(inmem_driver.delete_directory(folder.as_path()).await.is_ok());
}§Errors
Returns an error if the underlying Driver encounters an issue while
deleting the directory.
Sourcepub async fn last_modified(&self, path: &Path) -> DriverResult<SystemTime>
pub async fn last_modified(&self, path: &Path) -> DriverResult<SystemTime>
Retrieves the last modified timestamp of a file at the specified path within the storage.
§Parameters
path: The path to the file for which the last modified timestamp is retrieved.
§Examples
use std::path::PathBuf;
use active_storage::StoreConfig;
#[tokio::main]
async fn main() {
let inmem_driver = StoreConfig::InMem().build().await.unwrap();
let file_path = PathBuf::from("test.txt");
println!("{:#?}", inmem_driver.last_modified(file_path.as_path()).await);
}§Errors
Returns an error if the underlying Driver encounters an issue while
retrieving the timestamp.