Struct distant_protocol::Permissions
source · 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
impl Permissions
sourcepub fn readonly() -> Self
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));
sourcepub fn writable() -> Self
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));
sourcepub fn is_complete(&self) -> bool
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());
sourcepub fn is_readonly(&self) -> Option<bool>
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
);
sourcepub fn is_writable(&self) -> Option<bool>
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
);
sourcepub fn apply_from(&mut self, other: &Self)
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()
});
sourcepub fn apply_to(&self, other: &mut Self)
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()
});
sourcepub fn from_unix_mode(mode: u32) -> Self
pub fn from_unix_mode(mode: u32) -> Self
Converts a Unix mode
into the permission set.
sourcepub fn to_unix_mode(&self) -> u32
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
impl Clone for Permissions
source§fn clone(&self) -> Permissions
fn clone(&self) -> Permissions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Permissions
impl Debug for Permissions
source§impl Default for Permissions
impl Default for Permissions
source§fn default() -> Permissions
fn default() -> Permissions
source§impl<'de> Deserialize<'de> for Permissions
impl<'de> Deserialize<'de> for Permissions
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl From<Permissions> for Permissions
impl From<Permissions> for Permissions
source§fn from(permissions: Permissions) -> Self
fn from(permissions: Permissions) -> Self
Converts std::fs::Permissions
into Permissions
using
std::os::unix::fs::PermissionsExt::mode
to supply the bitset.
source§impl From<Permissions> for Permissions
impl From<Permissions> for Permissions
source§fn from(permissions: Permissions) -> Self
fn from(permissions: Permissions) -> Self
Converts Permissions
into std::fs::Permissions
using
std::os::unix::fs::PermissionsExt::from_mode
.
source§impl PartialEq<Permissions> for Permissions
impl PartialEq<Permissions> for Permissions
source§fn eq(&self, other: &Permissions) -> bool
fn eq(&self, other: &Permissions) -> bool
self
and other
values to be equal, and is used
by ==
.