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
impl Fs
sourcepub fn from_raw_map(fs: HashMap<OsString, Vec<u8>>) -> Self
pub fn from_raw_map(fs: HashMap<OsString, Vec<u8>>) -> Self
Create Fs
from a map of OsString
to Vec<u8>
.
sourcepub fn from_map(data: HashMap<String, impl Into<Vec<u8>>>) -> Self
pub fn from_map(data: HashMap<String, impl Into<Vec<u8>>>) -> Self
Create Fs
from a map of String
to Vec<u8>
.
sourcepub fn from_test_dir(
test_directory: impl Into<PathBuf>,
namespaced_to: impl Into<PathBuf>,
) -> Self
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");
sourcepub fn from_slice<'a>(files: &[(&'a str, &'a str)]) -> Self
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\"");
sourcepub async fn read_to_end(&self, path: impl AsRef<Path>) -> Result<Vec<u8>>
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.
Trait Implementations§
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> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreCreates a shared type from an unshared type.