pub trait CapStdExtDirExt {
    fn open_optional(&self, path: impl AsRef<Path>) -> Result<Option<File>>;
fn open_dir_optional(&self, path: impl AsRef<Path>) -> Result<Option<Dir>>;
fn ensure_dir_with(
        &self,
        p: impl AsRef<Path>,
        builder: &DirBuilder
    ) -> Result<bool>;
fn metadata_optional(
        &self,
        path: impl AsRef<Path>
    ) -> Result<Option<Metadata>>;
fn remove_file_optional(&self, path: impl AsRef<Path>) -> Result<bool>;
fn new_linkable_file<'p, 'd>(
        &'d self,
        path: &'p Path
    ) -> Result<LinkableTempfile<'p, 'd>>;
fn replace_file_with<F, T, E>(
        &self,
        destname: impl AsRef<Path>,
        f: F
    ) -> Result<T, E>
    where
        F: FnOnce(&mut BufWriter<LinkableTempfile<'_, '_>>) -> Result<T, E>,
        E: From<Error>
;
fn replace_file_with_perms<F, T, E>(
        &self,
        destname: impl AsRef<Path>,
        perms: Permissions,
        f: F
    ) -> Result<T, E>
    where
        F: FnOnce(&mut BufWriter<LinkableTempfile<'_, '_>>) -> Result<T, E>,
        E: From<Error>
;
fn replace_contents_with_perms(
        &self,
        destname: impl AsRef<Path>,
        contents: impl AsRef<[u8]>,
        perms: Permissions
    ) -> Result<()>; }
Expand description

Extension trait for cap_std::fs::Dir

Required methods

Open a file read-only, but return Ok(None) if it does not exist.

Open a directory, but return Ok(None) if it does not exist.

Create the target directory, but do nothing if a directory already exists at that path. The return value will be true if the directory was created. An error will be returned if the path is a non-directory. Symbolic links will be followed.

Gather metadata, but return Ok(None) if it does not exist.

Remove (delete) a file, but return Ok(false) if the file does not exist.

Create a new anonymous file that can be given a persistent name. On Linux, this uses O_TMPFILE if possible, otherwise a randomly named temporary file is used.

The file can later be linked into place once it has been completely written.

Atomically write a file, replacing an existing one (if present).

This wraps Self::new_linkable_file and crate::tempfile::LinkableTempfile::replace.

Atomically write a file using specified permissions, replacing an existing one (if present).

This wraps Self::new_linkable_file and crate::tempfile::LinkableTempfile::replace_with_perms.

Atomically write a file contents using specified permissions, replacing an existing one (if present).

This wraps Self::new_linkable_file and crate::tempfile::LinkableTempfile::replace_with_perms.

Implementations on Foreign Types

Implementors