Struct ndless::fs::Permissions
source · pub struct Permissions(/* private fields */);
Expand description
Representation of the various permissions on a file.
This module only currently provides one bit of information, readonly
,
which is exposed on all currently supported platforms. Unix-specific
functionality, such as mode bits, is available through the
PermissionsExt
trait.
Implementations§
source§impl Permissions
impl Permissions
sourcepub fn readonly(&self) -> bool
pub fn readonly(&self) -> bool
Returns true
if these permissions describe a readonly (unwritable) file.
§Examples
use std::fs::File;
fn main() -> std::io::Result<()> {
let mut f = File::create("foo.txt")?;
let metadata = f.metadata()?;
assert_eq!(false, metadata.permissions().readonly());
Ok(())
}
sourcepub fn set_readonly(&mut self, readonly: bool)
pub fn set_readonly(&mut self, readonly: bool)
Modifies the readonly flag for this set of permissions. If the
readonly
argument is true
, using the resulting Permission
will
update file permissions to forbid writing. Conversely, if it’s false
,
using the resulting Permission
will update file permissions to allow
writing.
This operation does not modify the filesystem.
§Examples
use std::fs::File;
fn main() -> std::io::Result<()> {
let f = File::create("foo.txt")?;
let metadata = f.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());
Ok(())
}
Trait Implementations§
source§impl Clone for Permissions
impl Clone for Permissions
source§fn clone(&self) -> Permissions
fn clone(&self) -> Permissions
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for Permissions
impl Debug for Permissions
source§impl PartialEq for Permissions
impl PartialEq for Permissions
source§fn eq(&self, other: &Permissions) -> bool
fn eq(&self, other: &Permissions) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Eq for Permissions
impl StructuralPartialEq for Permissions
Auto Trait Implementations§
impl RefUnwindSafe for Permissions
impl Send for Permissions
impl Sync for Permissions
impl Unpin for Permissions
impl UnwindSafe for Permissions
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more