pub struct WithCap<T> { /* private fields */ }Expand description
A wrapper that holds a type with a capability.
Implementations§
Source§impl<T> WithCap<T>
impl<T> WithCap<T>
Sourcepub const fn can_access(&self, cap: Cap) -> bool
pub const fn can_access(&self, cap: Cap) -> bool
Check if the inner data can be accessed with the given capability.
§Examples
use ax_cap_access::{Cap, WithCap};
let data = WithCap::new(42, Cap::READ);
assert!(data.can_access(Cap::READ));
assert!(!data.can_access(Cap::WRITE));Sourcepub unsafe fn access_unchecked(&self) -> &T
pub unsafe fn access_unchecked(&self) -> &T
Access the inner value without capability check.
§Safety
Caller must ensure not to violate the capability.
Sourcepub const fn access(&self, cap: Cap) -> Option<&T>
pub const fn access(&self, cap: Cap) -> Option<&T>
Access the inner value with the given capability, or return None
if cannot access.
§Examples
use ax_cap_access::{Cap, WithCap};
let data = WithCap::new(42, Cap::READ);
assert_eq!(data.access(Cap::READ).unwrap(), &42);
assert_eq!(data.access(Cap::WRITE), None);Sourcepub fn access_or_err<E>(&self, cap: Cap, err: E) -> Result<&T, E>
pub fn access_or_err<E>(&self, cap: Cap, err: E) -> Result<&T, E>
Access the inner value with the given capability, or return the given
err if cannot access.
§Examples
use ax_cap_access::{Cap, WithCap};
let data = WithCap::new(42, Cap::READ);
assert_eq!(data.access_or_err(Cap::READ, "cannot read").unwrap(), &42);
assert_eq!(
data.access_or_err(Cap::WRITE, "cannot write").err(),
Some("cannot write")
);Auto Trait Implementations§
impl<T> Freeze for WithCap<T>where
T: Freeze,
impl<T> RefUnwindSafe for WithCap<T>where
T: RefUnwindSafe,
impl<T> Send for WithCap<T>where
T: Send,
impl<T> Sync for WithCap<T>where
T: Sync,
impl<T> Unpin for WithCap<T>where
T: Unpin,
impl<T> UnsafeUnpin for WithCap<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for WithCap<T>where
T: UnwindSafe,
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