Trait Permissions

Source
pub trait Permissions:
    Clone
    + PartialEq
    + Eq
    + Debug {
    // Required methods
    fn readonly(&self) -> bool;
    fn set_readonly(&mut self, readonly: bool);
}
Expand description

Representation of the various permissions on a file.

This trait only requires readonly and set_readonly, which are the only two “cross platform” functions provided in std::fs. However, the unix_ext module has a useful PermissionsExt trait to complement this one.

Required Methods§

Source

fn readonly(&self) -> bool

Returns whether these permissions have readonly set.

§Examples
use rsfs::*;
use rsfs::mem::FS;
let fs = FS::new();

let file = fs.create_file("foo.txt")?;
let metadata = file.metadata()?;

assert_eq!(false, metadata.permissions().readonly());
Source

fn set_readonly(&mut self, readonly: bool)

Modifies the readonly fly for these permissions.

This does not modify the filesystem. To modify the filesystem, use the filesystem’s set_permissions function.

§Examples
use rsfs::*;
use rsfs::mem::FS;
let fs = FS::new();

let file = fs.create_file("foo.txt")?;
let metadata = file.metadata()?;
let mut permissions = metadata.permissions();

permissions.set_readonly(true);

// filesystem doesn't change
assert_eq!(false, metadata.permissions().readonly());

// just this particular `permissions`.
assert_eq!(true, permissions.readonly());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Permissions for rsfs::disk::Permissions

Source§

impl Permissions for rsfs::mem::Permissions

Source§

impl Permissions for rsfs::mem::unix::Permissions