pub struct FileRights(/* private fields */);Expand description
Used to reduce (but never expand) the capabilities on a file descriptor.
§See Also
§Example
let mut file = tempfile().unwrap();
FileRights::new()
.allow(Right::Read)
.limit(&file).unwrap();
capsicum::enter().unwrap();
let mut buf = vec![0u8; 80];
file.read(&mut buf[..]).unwrap();
let e = file.write(&buf[..]).unwrap_err();
assert_eq!(e.raw_os_error(), Some(libc::ENOTCAPABLE));Implementations§
Source§impl FileRights
impl FileRights
Sourcepub fn from_file<F: AsFd>(f: &F) -> Result<FileRights>
pub fn from_file<F: AsFd>(f: &F) -> Result<FileRights>
Sourcepub fn allow(&mut self, right: Right) -> &mut Self
pub fn allow(&mut self, right: Right) -> &mut Self
Add a new Right to the list of allowed rights.
Sourcepub fn contains(&self, other: &FileRights) -> bool
pub fn contains(&self, other: &FileRights) -> bool
Checks if self contains all of the rights present in other.
§Example
let mut rights1 = FileRights::new();
rights1.allow(Right::Read);
rights1.allow(Right::Write);
let mut rights2 = FileRights::new();
rights2.allow(Right::Write);
assert!(rights1.contains(&rights2));
let mut rights3 = FileRights::new();
rights3.allow(Right::Read);
rights3.allow(Right::Seek);
assert!(!rights1.contains(&rights3));pub fn is_valid(&self) -> bool
👎Deprecated since 0.4.0: Unnecessary unless you use FileRights::new
Sourcepub fn merge(&mut self, other: &FileRights) -> Result<()>
pub fn merge(&mut self, other: &FileRights) -> Result<()>
Add all rights present in other to this structure.
Sourcepub fn remove(&mut self, other: &FileRights) -> Result<()>
pub fn remove(&mut self, other: &FileRights) -> Result<()>
Remove any rights present in other from this structure, if they are set.
pub fn set(&mut self, raw_rights: Right) -> Result<()>
👎Deprecated since 0.4.0: use FileRights::allow instead
pub fn clear(&mut self, raw_rights: Right) -> Result<()>
👎Deprecated since 0.4.0: use FileRights::deny instead
Trait Implementations§
Source§impl CapRights for FileRights
impl CapRights for FileRights
Source§impl Clone for FileRights
impl Clone for FileRights
Source§fn clone(&self) -> FileRights
fn clone(&self) -> FileRights
Returns a duplicate 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 FileRights
impl Debug for FileRights
Source§impl Default for FileRights
impl Default for FileRights
Source§impl PartialEq for FileRights
impl PartialEq for FileRights
impl Copy for FileRights
impl Eq for FileRights
impl StructuralPartialEq for FileRights
Auto Trait Implementations§
impl Freeze for FileRights
impl RefUnwindSafe for FileRights
impl Send for FileRights
impl Sync for FileRights
impl Unpin for FileRights
impl UnwindSafe for FileRights
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