pub struct Filesystem { /* private fields */ }Expand description
Dependency client for small read and write file operations.
This client intentionally mirrors the corresponding std::fs helpers
instead of modeling a full virtual file system.
§Examples
use std::time::{SystemTime, UNIX_EPOCH};
let filesystem = clients::get::<clients::Filesystem>();
let unique = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time should be after the unix epoch")
.as_nanos();
let path = std::env::temp_dir().join(format!("clients-doc-filesystem-{unique}.txt"));
filesystem
.write_string(path.clone(), "hello".to_string())
.expect("write should succeed");
assert_eq!(
filesystem.read_string(path.clone()).expect("read should succeed"),
"hello"
);
std::fs::remove_file(path).expect("temp file should be removable");Implementations§
Source§impl Filesystem
impl Filesystem
Sourcepub fn read(&self, path: PathBuf) -> Result<Vec<u8>, IoError>
pub fn read(&self, path: PathBuf) -> Result<Vec<u8>, IoError>
Reads the file at path into memory as raw bytes.
Sourcepub fn read_string(&self, path: PathBuf) -> Result<String, IoError>
pub fn read_string(&self, path: PathBuf) -> Result<String, IoError>
Reads the file at path into memory as a UTF-8 string.
Trait Implementations§
Source§impl Clone for Filesystem
impl Clone for Filesystem
Source§fn clone(&self) -> Filesystem
fn clone(&self) -> Filesystem
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for Filesystem
impl Default for Filesystem
Source§impl Dependency for Filesystem
impl Dependency for Filesystem
impl Copy for Filesystem
Auto Trait Implementations§
impl Freeze for Filesystem
impl RefUnwindSafe for Filesystem
impl Send for Filesystem
impl Sync for Filesystem
impl Unpin for Filesystem
impl UnsafeUnpin for Filesystem
impl UnwindSafe for Filesystem
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