Crate capability
source ·Expand description
Provide basic capability-based security.
The wrapper type WithCap
associates a capability to an object, that
is a set of access rights. When accessing the object, we must explicitly
specify the access capability, and it must not violate the capability
associated with the object at initialization.
Examples
use capability::{Cap, WithCap};
let data = WithCap::new(42, Cap::READ | Cap::WRITE);
// Access with the correct capability.
assert_eq!(data.access(Cap::READ).unwrap(), &42);
assert_eq!(data.access(Cap::WRITE).unwrap(), &42);
assert_eq!(data.access(Cap::READ | Cap::WRITE).unwrap(), &42);
// Access with the incorrect capability.
assert!(data.access(Cap::EXECUTE).is_err());
assert!(data.access(Cap::READ | Cap::EXECUTE).is_err());
Structs
- Capabilities (access rights).
- Error type for capability violation.
- A wrapper that holds a type with a capability.