pub struct Permissions {
    pub owner_read: Option<bool>,
    pub owner_write: Option<bool>,
    pub owner_exec: Option<bool>,
    pub group_read: Option<bool>,
    pub group_write: Option<bool>,
    pub group_exec: Option<bool>,
    pub other_read: Option<bool>,
    pub other_write: Option<bool>,
    pub other_exec: Option<bool>,
}
Expand description

Represents permissions to apply to some path on a remote machine

When used to set permissions on a file, directory, or symlink, only fields that are set (not None) will be applied.

On Unix platforms, this translates directly into the mode that you would find with chmod. On all other platforms, this uses the write flags to determine whether or not to set the readonly status.

Fields§

§owner_read: Option<bool>

Represents whether or not owner can read from the file

§owner_write: Option<bool>

Represents whether or not owner can write to the file

§owner_exec: Option<bool>

Represents whether or not owner can execute the file

§group_read: Option<bool>

Represents whether or not associated group can read from the file

§group_write: Option<bool>

Represents whether or not associated group can write to the file

§group_exec: Option<bool>

Represents whether or not associated group can execute the file

§other_read: Option<bool>

Represents whether or not other can read from the file

§other_write: Option<bool>

Represents whether or not other can write to the file

§other_exec: Option<bool>

Represents whether or not other can execute the file

Implementations§

source§

impl Permissions

source

pub fn readonly() -> Self

Creates a set of Permissions that indicate readonly status.

use distant_protocol::Permissions;

let permissions = Permissions::readonly();
assert_eq!(permissions.is_readonly(), Some(true));
assert_eq!(permissions.is_writable(), Some(false));
source

pub fn writable() -> Self

Creates a set of Permissions that indicate globally writable status.

use distant_protocol::Permissions;

let permissions = Permissions::writable();
assert_eq!(permissions.is_readonly(), Some(false));
assert_eq!(permissions.is_writable(), Some(true));
source

pub fn is_complete(&self) -> bool

Returns true if the permission set has a value specified for each permission (no None settings).

use distant_protocol::Permissions;

let permissions = Permissions {
    owner_write: Some(true),
    group_write: Some(false),
    other_write: Some(true),
    owner_read: Some(false),
    group_read: Some(true),
    other_read: Some(false),
    owner_exec: Some(true),
    group_exec: Some(false),
    other_exec: Some(true),
};
assert!(permissions.is_complete());
source

pub fn is_readonly(&self) -> Option<bool>

Returns true if permissions represent readonly, false if permissions represent writable, and None if no permissions have been set to indicate either status.

use distant_protocol::Permissions;

assert_eq!(
    Permissions { owner_write: Some(true), ..Default::default() }.is_readonly(),
    Some(false)
);

assert_eq!(
    Permissions { owner_write: Some(false), ..Default::default() }.is_readonly(),
    Some(true)
);

assert_eq!(
    Permissions { ..Default::default() }.is_writable(),
    None
);
source

pub fn is_writable(&self) -> Option<bool>

Returns true if permissions represent ability to write, false if permissions represent inability to write, and None if no permissions have been set to indicate either status.

use distant_protocol::Permissions;

assert_eq!(
    Permissions { owner_write: Some(true), ..Default::default() }.is_writable(),
    Some(true)
);

assert_eq!(
    Permissions { owner_write: Some(false), ..Default::default() }.is_writable(),
    Some(false)
);

assert_eq!(
    Permissions { ..Default::default() }.is_writable(),
    None
);
source

pub fn apply_from(&mut self, other: &Self)

Applies other settings to self, overwriting any of the permissions in self with other.

use distant_protocol::Permissions;

let mut a = Permissions {
    owner_read: Some(true),
    owner_write: Some(false),
    owner_exec: None,
    ..Default::default()
};

let b = Permissions {
    owner_read: Some(false),
    owner_write: None,
    owner_exec: Some(true),
    ..Default::default()
};

a.apply_from(&b);

assert_eq!(a, Permissions {
    owner_read: Some(false),
    owner_write: Some(false),
    owner_exec: Some(true),
    ..Default::default()
});
source

pub fn apply_to(&self, other: &mut Self)

Applies self settings to other, overwriting any of the permissions in other with self.

use distant_protocol::Permissions;

let a = Permissions {
    owner_read: Some(true),
    owner_write: Some(false),
    owner_exec: None,
    ..Default::default()
};

let mut b = Permissions {
    owner_read: Some(false),
    owner_write: None,
    owner_exec: Some(true),
    ..Default::default()
};

a.apply_to(&mut b);

assert_eq!(b, Permissions {
    owner_read: Some(true),
    owner_write: Some(false),
    owner_exec: Some(true),
    ..Default::default()
});
source

pub fn from_unix_mode(mode: u32) -> Self

Converts a Unix mode into the permission set.

source

pub fn to_unix_mode(&self) -> u32

Converts to a Unix mode from a permission set. For any missing setting, a 0 bit is used.

use distant_protocol::Permissions;

assert_eq!(Permissions {
    owner_read: Some(true),
    owner_write: Some(true),
    owner_exec: Some(true),
    group_read: Some(true),
    group_write: Some(true),
    group_exec: Some(true),
    other_read: Some(true),
    other_write: Some(true),
    other_exec: Some(true),
}.to_unix_mode(), 0o777);

assert_eq!(Permissions {
    owner_read: Some(true),
    owner_write: Some(false),
    owner_exec: Some(false),
    group_read: Some(true),
    group_write: Some(false),
    group_exec: Some(false),
    other_read: Some(true),
    other_write: Some(false),
    other_exec: Some(false),
}.to_unix_mode(), 0o444);

assert_eq!(Permissions {
    owner_exec: Some(true),
    group_exec: Some(true),
    other_exec: Some(true),
    ..Default::default()
}.to_unix_mode(), 0o111);

Trait Implementations§

source§

impl Clone for Permissions

source§

fn clone(&self) -> Permissions

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Permissions

source§

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

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

impl Default for Permissions

source§

fn default() -> Permissions

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

impl<'de> Deserialize<'de> for Permissions

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Permissions> for Permissions

source§

impl From<Permissions> for Permissions

source§

fn from(permissions: Permissions) -> Self

source§

impl PartialEq<Permissions> for Permissions

source§

fn eq(&self, other: &Permissions) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Permissions

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Permissions

source§

impl Eq for Permissions

source§

impl StructuralEq for Permissions

source§

impl StructuralPartialEq for Permissions

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,