Trait zng_task::fs::unix::PermissionsExt
1.1.0 · source · pub trait PermissionsExt {
// Required methods
fn mode(&self) -> u32;
fn set_mode(&mut self, mode: u32);
fn from_mode(mode: u32) -> Self;
}
Expand description
Unix-specific extensions to fs::Permissions
.
Required Methods§
1.1.0 · sourcefn mode(&self) -> u32
fn mode(&self) -> u32
Returns the underlying raw st_mode
bits that contain the standard
Unix permissions for this file.
§Examples
use std::fs::File;
use std::os::unix::fs::PermissionsExt;
fn main() -> std::io::Result<()> {
let f = File::create("foo.txt")?;
let metadata = f.metadata()?;
let permissions = metadata.permissions();
println!("permissions: {:o}", permissions.mode());
Ok(())
}
1.1.0 · sourcefn set_mode(&mut self, mode: u32)
fn set_mode(&mut self, mode: u32)
Sets the underlying raw bits for this set of permissions.
§Examples
use std::fs::File;
use std::os::unix::fs::PermissionsExt;
fn main() -> std::io::Result<()> {
let f = File::create("foo.txt")?;
let metadata = f.metadata()?;
let mut permissions = metadata.permissions();
permissions.set_mode(0o644); // Read/write for owner and read for others.
assert_eq!(permissions.mode(), 0o644);
Ok(())
}
1.1.0 · sourcefn from_mode(mode: u32) -> Self
fn from_mode(mode: u32) -> Self
Creates a new instance of Permissions
from the given set of Unix
permission bits.
§Examples
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;
// Read/write for owner and read for others.
let permissions = Permissions::from_mode(0o644);
assert_eq!(permissions.mode(), 0o644);
Object Safety§
This trait is not object safe.