Skip to main content

PosixFs

Struct PosixFs 

Source
pub struct PosixFs<B: FsBackend> { /* private fields */ }
Expand description

POSIX-compatible filesystem wrapper.

Wraps any FsBackend and enforces POSIX-like semantics.

§Semantics Enforced

OperationCheck
write_fileFails if path is a directory
append_fileFails if path is a directory
mkdirFails if path exists as file (always) or dir (unless recursive)
read_dirFails if path is not a directory
copyFails if source is a directory

§Example

use bashkit::{FsBackend, PosixFs, Bash};
use std::sync::Arc;

// Your simple storage backend
let backend = MyStorage::new();

// Wrap with PosixFs for POSIX semantics
let fs = Arc::new(PosixFs::new(backend));

// Use with Bash interpreter
let mut bash = Bash::builder().fs(fs).build();

Implementations§

Source§

impl<B: FsBackend> PosixFs<B>

Source

pub fn new(backend: B) -> Self

Create a new POSIX-compatible filesystem wrapper.

Source

pub fn backend(&self) -> &B

Get a reference to the underlying backend.

Trait Implementations§

Source§

impl<B: FsBackend + 'static> FileSystem for PosixFs<B>

Source§

fn read_file<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a file’s contents as bytes. Read more
Source§

fn write_file<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 Path, content: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Write contents to a file, creating it if necessary. Read more
Source§

fn append_file<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 Path, content: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Append contents to a file, creating it if necessary. Read more
Source§

fn mkdir<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, recursive: bool, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a directory. Read more
Source§

fn remove<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, recursive: bool, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remove a file or directory. Read more
Source§

fn stat<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, ) -> Pin<Box<dyn Future<Output = Result<Metadata>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get file or directory metadata. Read more
Source§

fn read_dir<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, ) -> Pin<Box<dyn Future<Output = Result<Vec<DirEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List directory contents. Read more
Source§

fn exists<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Check if a path exists. Read more
Source§

fn rename<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, from: &'life1 Path, to: &'life2 Path, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Rename or move a file or directory. Read more
Source§

fn copy<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, from: &'life1 Path, to: &'life2 Path, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Copy a file. Read more
Create a symbolic link. Read more
Read a symbolic link’s target. Read more
Source§

fn chmod<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, mode: u32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Change file permissions. Read more
Source§

fn usage(&self) -> FsUsage

Get current filesystem usage statistics. Read more
Source§

fn limits(&self) -> FsLimits

Get filesystem limits. Read more
Source§

impl<B: FsBackend + 'static> From<PosixFs<B>> for Arc<dyn FileSystem>

Source§

fn from(fs: PosixFs<B>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<B> Freeze for PosixFs<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for PosixFs<B>
where B: RefUnwindSafe,

§

impl<B> Send for PosixFs<B>

§

impl<B> Sync for PosixFs<B>

§

impl<B> Unpin for PosixFs<B>
where B: Unpin,

§

impl<B> UnwindSafe for PosixFs<B>
where B: UnwindSafe,

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