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:
ELOOPon Unix andERROR_CANT_RESOLVE_FILENAME(1921) on Windows map toFsError::SymlinkLoop.EISDIRon Unix maps toFsError::NotAFilewhen surfaced fromread; on WindowsERROR_ACCESS_DENIEDis overloaded with genuine permission failures and is NOT remapped here.ENOTDIRon Unix andERROR_DIRECTORY(267) on Windows map toFsError::NotADirectorywhen surfaced fromread_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
impl StdFilesystem
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Construct a new StdFilesystem.
Trait Implementations§
Source§impl Clone for StdFilesystem
impl Clone for StdFilesystem
Source§fn clone(&self) -> StdFilesystem
fn clone(&self) -> StdFilesystem
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for StdFilesystem
Source§impl Debug for StdFilesystem
impl Debug for StdFilesystem
Source§impl Default for StdFilesystem
impl Default for StdFilesystem
Source§fn default() -> StdFilesystem
fn default() -> StdFilesystem
Source§impl Filesystem for StdFilesystem
impl Filesystem for StdFilesystem
Source§type CanonicalPath = StdCanonicalPath
type CanonicalPath = StdCanonicalPath
Filesystem::canonicalize. Read moreSource§fn metadata(&self, path: &Path) -> Result<FsMetadata, FsError>
fn metadata(&self, path: &Path) -> Result<FsMetadata, FsError>
path, FOLLOWING symlinks.
If path is a symlink, the returned metadata describes the
target. Read moreSource§fn symlink_metadata(&self, path: &Path) -> Result<FsMetadata, FsError>
fn symlink_metadata(&self, path: &Path) -> Result<FsMetadata, FsError>
path, WITHOUT following a
trailing symlink. Intermediate symlinks in the path are
followed; only the last component is returned as-is. Read moreSource§fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>, FsError>
fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>, FsError>
path. The order of
the returned entries is implementation-defined; callers MUST
NOT depend on a particular order. Read moreSource§fn read(&self, path: &Path) -> Result<Vec<u8>, FsError>
fn read(&self, path: &Path) -> Result<Vec<u8>, FsError>
path and return its raw bytes.
Symlinks in any component (including the last) are followed. Read moreSource§fn permissions(&self, path: &Path) -> Result<u32, FsError>
fn permissions(&self, path: &Path) -> Result<u32, FsError>
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 moreSource§fn canonicalize(&self, path: &Path) -> Result<Self::CanonicalPath, FsError>
fn canonicalize(&self, path: &Path) -> Result<Self::CanonicalPath, FsError>
. / .. 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 moreSource§impl WritableFilesystem for StdFilesystem
impl WritableFilesystem for StdFilesystem
Source§fn create_dir_all(&self, path: &Path) -> Result<(), FsError>
fn create_dir_all(&self, path: &Path) -> Result<(), FsError>
path along with any missing
intermediate components. Idempotent: succeeds when path
already exists as a directory. Read moreSource§fn write_file(&self, path: &Path, contents: &[u8]) -> Result<(), FsError>
fn write_file(&self, path: &Path, contents: &[u8]) -> Result<(), FsError>
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 moreSource§fn rename(&self, from: &Path, to: &Path) -> Result<(), FsError>
fn rename(&self, from: &Path, to: &Path) -> Result<(), FsError>
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 moreSource§fn remove_dir_all(&self, path: &Path) -> Result<(), FsError>
fn remove_dir_all(&self, path: &Path) -> Result<(), FsError>
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 moreSource§fn set_permissions(&self, path: &Path, mode: u32) -> Result<(), FsError>
fn set_permissions(&self, path: &Path, mode: u32) -> Result<(), FsError>
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 moreSource§fn fsync_file(&self, path: &Path) -> Result<(), FsError>
fn fsync_file(&self, path: &Path) -> Result<(), FsError>
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 moreSource§fn fsync_dir(&self, path: &Path) -> Result<(), FsError>
fn fsync_dir(&self, path: &Path) -> Result<(), FsError>
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