Struct aws_types::os_shim_internal::Fs

source ·
pub struct Fs(/* private fields */);
Expand description

File system abstraction

Simple abstraction enabling in-memory mocking of the file system

§Examples

Construct a file system which delegates to std::fs:

let fs = aws_types::os_shim_internal::Fs::real();

Construct an in-memory file system for testing:

use std::collections::HashMap;
let fs = aws_types::os_shim_internal::Fs::from_map({
    let mut map = HashMap::new();
    map.insert("/home/.aws/config".to_string(), "[default]\nregion = us-east-1");
    map
});

Implementations§

source§

impl Fs

source

pub fn real() -> Self

Create Fs representing a real file system.

source

pub fn from_raw_map(fs: HashMap<OsString, Vec<u8>>) -> Self

Create Fs from a map of OsString to Vec<u8>.

source

pub fn from_map(data: HashMap<String, impl Into<Vec<u8>>>) -> Self

Create Fs from a map of String to Vec<u8>.

source

pub fn from_test_dir( test_directory: impl Into<PathBuf>, namespaced_to: impl Into<PathBuf>, ) -> Self

Create a test filesystem rooted in real files

Creates a test filesystem from the contents of test_directory rooted into namespaced_to.

Example: Given:

$ ls
./my-test-dir/aws-config
./my-test-dir/aws-config/config
$ cat ./my-test-dir/aws-config/config
test-config
use aws_types::os_shim_internal::{Env, Fs};
let env = Env::from_slice(&[("HOME", "/Users/me")]);
let fs = Fs::from_test_dir("my-test-dir/aws-config", "/Users/me/.aws/config");
assert_eq!(fs.read_to_end("/Users/me/.aws/config").await.unwrap(), b"test-config");
source

pub fn from_slice<'a>(files: &[(&'a str, &'a str)]) -> Self

Create a fake process environment from a slice of tuples.

§Examples
use aws_types::os_shim_internal::Fs;
let mock_fs = Fs::from_slice(&[
    ("config", "[default]\nretry_mode = \"standard\""),
]);
assert_eq!(mock_fs.read_to_end("config").await.unwrap(), b"[default]\nretry_mode = \"standard\"");
source

pub async fn read_to_end(&self, path: impl AsRef<Path>) -> Result<Vec<u8>>

Read the entire contents of a file

Note: This function is currently async primarily for forward compatibility. Currently, this function does not use Tokio (or any other runtime) to perform IO, the IO is performed directly within the function.

source

pub async fn write( &self, path: impl AsRef<Path>, contents: impl AsRef<[u8]>, ) -> Result<()>

Write a slice as the entire contents of a file.

This is equivalent to std::fs::write.

Trait Implementations§

source§

impl Clone for Fs

source§

fn clone(&self) -> Fs

Returns a copy 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 Debug for Fs

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Fs

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Fs

§

impl RefUnwindSafe for Fs

§

impl Send for Fs

§

impl Sync for Fs

§

impl Unpin for Fs

§

impl UnwindSafe for Fs

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more