Skip to main content

StdFilesystem

Struct StdFilesystem 

Source
pub struct StdFilesystem;
Expand description

Filesystem implementation backed by std::fs.

Every method delegates directly to the standard library. Symlink semantics, depth caps, and platform-specific path normalisation are whatever std::fs provides on the host platform.

OS errors are translated to the trait-level vocabulary by inspecting raw_os_error:

  • ELOOP on Unix and ERROR_CANT_RESOLVE_FILENAME (1921) on Windows map to FsError::SymlinkLoop.
  • EISDIR on Unix maps to FsError::NotAFile when surfaced from read; on Windows ERROR_ACCESS_DENIED is overloaded with genuine permission failures and is NOT remapped here.
  • ENOTDIR on Unix and ERROR_DIRECTORY (267) on Windows map to FsError::NotADirectory when surfaced from read_dir.

Every other I/O error falls through to FsError::Io.

read performs an additional Filesystem::metadata pre-check before delegating to std::fs::read: the OS does not surface “not a regular file” through a single error code (FIFO opens block, char-device opens succeed, sockets emit ENXIO), so a kind check by stat is the only way to honour the FsError::NotAFile contract for those kinds. The EISDIR translation remains in place as a TOCTOU backstop.

Implementations§

Source§

impl StdFilesystem

Source

pub const fn new() -> Self

Construct a new StdFilesystem.

Trait Implementations§

Source§

impl Clone for StdFilesystem

Source§

fn clone(&self) -> StdFilesystem

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for StdFilesystem

Source§

impl Debug for StdFilesystem

Source§

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

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

impl Default for StdFilesystem

Source§

fn default() -> StdFilesystem

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

impl Filesystem for StdFilesystem

Source§

type CanonicalPath = StdCanonicalPath

The implementation-specific canonical-path type produced by Filesystem::canonicalize. Read more
Source§

fn metadata(&self, path: &Path) -> Result<FsMetadata, FsError>

Return metadata for the entry at path, FOLLOWING symlinks. If path is a symlink, the returned metadata describes the target. Read more
Return metadata for the entry at path, WITHOUT following a trailing symlink. Intermediate symlinks in the path are followed; only the last component is returned as-is. Read more
Source§

fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>, FsError>

Read all entries in the directory at path. The order of the returned entries is implementation-defined; callers MUST NOT depend on a particular order. Read more
Source§

fn read(&self, path: &Path) -> Result<Vec<u8>, FsError>

Read the entire file at path and return its raw bytes. Symlinks in any component (including the last) are followed. Read more
Source§

fn permissions(&self, path: &Path) -> Result<u32, FsError>

Return the Unix permission bits of the regular file at path, masked to the low 12 bits (the conventional S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX range). Symlinks in any component (including the last) are followed, matching Self::read’s semantics. Read more
Source§

fn canonicalize(&self, path: &Path) -> Result<Self::CanonicalPath, FsError>

Resolve all symlinks and . / .. components in path and return the canonical absolute path as the implementation’s Self::CanonicalPath type. Every intermediate and terminal symlink is followed; the implementation MUST detect cycles and depth-cap exhaustion as FsError::SymlinkLoop. Read more
Read the target of the symlink at path. Does NOT follow the symlink itself (that would defeat the purpose); intermediate components ARE resolved as usual. Read more
Source§

impl WritableFilesystem for StdFilesystem

Source§

fn create_dir_all(&self, path: &Path) -> Result<(), FsError>

Create the directory at path along with any missing intermediate components. Idempotent: succeeds when path already exists as a directory. Read more
Source§

fn write_file(&self, path: &Path, contents: &[u8]) -> Result<(), FsError>

Write contents to path, overwriting any existing file. The immediate parent directory MUST already exist; the method does NOT create it (use Self::create_dir_all beforehand). Read more
Source§

fn rename(&self, from: &Path, to: &Path) -> Result<(), FsError>

Rename from to to. On Unix this is rename(2); on Windows it is MoveFileExW with MOVEFILE_REPLACE_EXISTING. When to exists, it is atomically replaced (subject to the host platform’s guarantees; same filesystem only on Unix). Read more
Source§

fn remove_dir_all(&self, path: &Path) -> Result<(), FsError>

Recursively remove path and every entry below it. Idempotent on missing paths: a path that does not exist returns FsError::NotFound; callers that want a true “remove if exists” pre-check with Filesystem::metadata. Read more
Source§

fn set_permissions(&self, path: &Path, mode: u32) -> Result<(), FsError>

Set the Unix permission bits on path to mode (the low 12 bits of mode correspond to the POSIX S_IRWXU, S_IRWXG, S_IRWXO, S_ISUID, S_ISGID, S_ISVTX bits). Read more
Source§

fn fsync_file(&self, path: &Path) -> Result<(), FsError>

Flush the contents and metadata of the file at path to durable storage. On Unix this is fsync(2) on an open(2)-ed descriptor; on Windows this is FlushFileBuffers. On in-memory implementations this is a documented no-op. Read more
Source§

fn fsync_dir(&self, path: &Path) -> Result<(), FsError>

Flush the entry list of the directory at path to durable storage. POSIX requires this after rename(2) to make the rename itself durable across power loss. On Windows this MAY be a no-op (the platform does not expose the operation for directories). On in-memory implementations this is a documented no-op. Read more

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.