Skip to main content

Filesystem

Struct Filesystem 

Source
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

Source

pub fn read(&self, path: PathBuf) -> Result<Vec<u8>, IoError>

Reads the file at path into memory as raw bytes.

Source

pub fn read_string(&self, path: PathBuf) -> Result<String, IoError>

Reads the file at path into memory as a UTF-8 string.

Source

pub fn write(&self, path: PathBuf, contents: Vec<u8>) -> Result<(), IoError>

Writes contents to path, replacing any existing file.

Source

pub fn write_string( &self, path: PathBuf, contents: String, ) -> Result<(), IoError>

Writes contents to path, replacing any existing file.

Trait Implementations§

Source§

impl Clone for Filesystem

Source§

fn clone(&self) -> Filesystem

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Filesystem

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Dependency for Filesystem

Source§

fn live() -> Self

Returns the live value for this dependency type.
Source§

impl Copy for Filesystem

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V