Skip to main content

Filesystem

Struct Filesystem 

Source
pub struct Filesystem;
Expand description

Stateless host-filesystem operations.

All methods are free functions on &Path. There is no instance state.

Matches the surface of oa::Filesystem in C++ and its Python bindings so that cross-language code reads identically:

ⓘ
Filesystem::create_directories(output.parent().unwrap())?;
let text = Filesystem::read_text(&config_path)?;

Implementations§

Source§

impl Filesystem

Source

pub fn exists(path: &Path) -> bool

Return true if path exists (file, directory, or symlink target).

Source

pub fn is_file(path: &Path) -> bool

Return true if path is a regular file.

Source

pub fn is_directory(path: &Path) -> bool

Return true if path is a directory.

Source

pub fn get_file_size(path: &Path) -> Result<u64>

Return the byte size of the file at path.

Source

pub fn get_last_modified(path: &Path) -> Result<i64>

Return the last-modified time as seconds since the Unix epoch.

Matches oa::Filesystem::getLastModified which returns an i64 Unix timestamp.

Source

pub fn create_directory(path: &Path) -> Result<()>

Create a single directory. Succeeds silently if it already exists.

Source

pub fn create_directories(path: &Path) -> Result<()>

Create a directory and all missing ancestors. Succeeds silently if the full path already exists as a directory.

Source

pub fn remove_file(path: &Path) -> Result<()>

Remove a file. Succeeds silently if the file does not exist.

Source

pub fn remove_directory(path: &Path, recursive: bool) -> Result<()>

Remove a directory.

When recursive is false the directory must be empty. When true the entire subtree is removed. Succeeds silently if the path does not exist.

Source

pub fn copy(from: &Path, to: &Path) -> Result<()>

Copy a file or directory.

For a directory, creates the destination directory (non-recursive). For a file, reads the source and writes it to the destination, creating parent directories as needed.

Source

pub fn move_path(from: &Path, to: &Path) -> Result<()>

Move (rename) a path. Creates parent directories of the destination.

Note: cannot be named move in Rust (reserved keyword).

Source

pub fn list_files(dir: &Path, extension: &str) -> Result<Vec<PathBuf>>

List regular files in dir, optionally filtered by extension.

extension is matched against the full extension string including the leading . (e.g. ".png"). Pass "" to return all files. Results are sorted lexicographically.

Source

pub fn list_directories(dir: &Path) -> Result<Vec<PathBuf>>

List immediate sub-directories of dir. Symlinks are not followed. Results are sorted lexicographically.

Source

pub fn list_all(dir: &Path, recursive: bool) -> Result<Vec<PathBuf>>

List all entries (files and directories) in dir.

When recursive is true, descends into sub-directories but does not follow symlinks. Results are sorted lexicographically.

Source

pub fn read_text(path: &Path) -> Result<String>

Read the entire file as a UTF-8 string.

Source

pub fn write_text(path: &Path, content: &str) -> Result<()>

Write content to a file, creating parent directories as needed. Truncates any existing content.

Source

pub fn append_text(path: &Path, content: &str) -> Result<()>

Append content to a file, creating parent directories as needed.

Source

pub fn read_lines(path: &Path) -> Result<Vec<String>>

Read lines, stripping \r\n and \n line endings. The final line is included even if it lacks a trailing newline. Empty files return an empty Vec.

Source

pub fn read_binary(path: &Path) -> Result<Vec<u8>>

Read the entire file as raw bytes.

Source

pub fn write_binary(path: &Path, data: &[u8]) -> Result<()>

Write data to a file, creating parent directories as needed. Truncates any existing content.

Source

pub fn absolute(path: &Path) -> Result<PathBuf>

Resolve a path to an absolute path against the current working directory. Does not require the path to exist.

Source

pub fn glob(dir: &Path, pattern: &str) -> Result<Vec<PathBuf>>

Return the files in dir whose filename matches pattern.

* matches any sequence of characters; ? matches exactly one character. Only the filename component is matched, not the full path. Results are sorted lexicographically.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.