pub struct Capability(/* private fields */);Expand description
Logical capabilities that a context can grant to child entities.
Each capability gates a set of operations. Operations require the corresponding capability to be present in the context.
Implementations§
Source§impl Capability
impl Capability
Sourcepub const READ: Capability
pub const READ: Capability
Read files: orcs.read, orcs.grep, orcs.glob
Sourcepub const WRITE: Capability
pub const WRITE: Capability
Write files: orcs.write, orcs.mkdir
Sourcepub const DELETE: Capability
pub const DELETE: Capability
Delete/move files: orcs.remove, orcs.mv
Sourcepub const EXECUTE: Capability
pub const EXECUTE: Capability
Execute commands: orcs.exec
Sourcepub const SPAWN: Capability
pub const SPAWN: Capability
Spawn children/runners: orcs.spawn_child, orcs.spawn_runner
Sourcepub const LLM: Capability
pub const LLM: Capability
Call LLM: orcs.llm
Sourcepub const HTTP: Capability
pub const HTTP: Capability
HTTP requests: orcs.http
Source§impl Capability
impl Capability
Sourcepub const fn empty() -> Capability
pub const fn empty() -> Capability
Get a flags value with all bits unset.
Sourcepub const fn all() -> Capability
pub const fn all() -> Capability
Get a flags value with all known bits set.
Sourcepub const fn bits(&self) -> u16
pub const fn bits(&self) -> u16
Get the underlying bits value.
The returned value is exactly the bits set in this flags value.
Sourcepub const fn from_bits(bits: u16) -> Option<Capability>
pub const fn from_bits(bits: u16) -> Option<Capability>
Convert from a bits value.
This method will return None if any unknown bits are set.
Sourcepub const fn from_bits_truncate(bits: u16) -> Capability
pub const fn from_bits_truncate(bits: u16) -> Capability
Convert from a bits value, unsetting any unknown bits.
Sourcepub const fn from_bits_retain(bits: u16) -> Capability
pub const fn from_bits_retain(bits: u16) -> Capability
Convert from a bits value exactly.
Sourcepub fn from_name(name: &str) -> Option<Capability>
pub fn from_name(name: &str) -> Option<Capability>
Get a flags value with the bits of a flag with the given name set.
This method will return None if name is empty or doesn’t
correspond to any named flag.
Sourcepub const fn intersects(&self, other: Capability) -> bool
pub const fn intersects(&self, other: Capability) -> bool
Whether any set bits in a source flags value are also set in a target flags value.
Sourcepub const fn contains(&self, other: Capability) -> bool
pub const fn contains(&self, other: Capability) -> bool
Whether all set bits in a source flags value are also set in a target flags value.
Sourcepub fn insert(&mut self, other: Capability)
pub fn insert(&mut self, other: Capability)
The bitwise or (|) of the bits in two flags values.
Sourcepub fn remove(&mut self, other: Capability)
pub fn remove(&mut self, other: Capability)
The intersection of a source flags value with the complement of a target flags
value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
remove won’t truncate other, but the ! operator will.
Sourcepub fn toggle(&mut self, other: Capability)
pub fn toggle(&mut self, other: Capability)
The bitwise exclusive-or (^) of the bits in two flags values.
Sourcepub fn set(&mut self, other: Capability, value: bool)
pub fn set(&mut self, other: Capability, value: bool)
Call insert when value is true or remove when value is false.
Sourcepub const fn intersection(self, other: Capability) -> Capability
pub const fn intersection(self, other: Capability) -> Capability
The bitwise and (&) of the bits in two flags values.
Sourcepub const fn union(self, other: Capability) -> Capability
pub const fn union(self, other: Capability) -> Capability
The bitwise or (|) of the bits in two flags values.
Sourcepub const fn difference(self, other: Capability) -> Capability
pub const fn difference(self, other: Capability) -> Capability
The intersection of a source flags value with the complement of a target flags
value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.
Sourcepub const fn symmetric_difference(self, other: Capability) -> Capability
pub const fn symmetric_difference(self, other: Capability) -> Capability
The bitwise exclusive-or (^) of the bits in two flags values.
Sourcepub const fn complement(self) -> Capability
pub const fn complement(self) -> Capability
The bitwise negation (!) of the bits in a flags value, truncating the result.
Source§impl Capability
impl Capability
Sourcepub const fn iter(&self) -> Iter<Capability>
pub const fn iter(&self) -> Iter<Capability>
Yield a set of contained flags values.
Each yielded flags value will correspond to a defined named flag. Any unknown bits will be yielded together as a final flags value.
Sourcepub const fn iter_names(&self) -> IterNames<Capability>
pub const fn iter_names(&self) -> IterNames<Capability>
Yield a set of contained named flags values.
This method is like iter, except only yields bits in contained named flags.
Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
Source§impl Capability
impl Capability
Sourcepub const FILE_ALL: Capability
pub const FILE_ALL: Capability
All file operations: READ | WRITE | DELETE.
Sourcepub const ALL: Capability
pub const ALL: Capability
All capabilities.
Sourcepub fn inherit(parent: Capability, requested: Capability) -> Capability
pub fn inherit(parent: Capability, requested: Capability) -> Capability
Computes the effective capabilities for a child.
Returns the intersection of parent and requested capabilities. A child can never exceed its parent’s capabilities.
§Arguments
parent- Parent’s capabilitiesrequested- Requested capabilities for the child
§Returns
parent & requested — the effective capability set.
§Example
use orcs_auth::Capability;
let parent = Capability::READ | Capability::WRITE;
let requested = Capability::READ | Capability::EXECUTE;
let effective = Capability::inherit(parent, requested);
assert_eq!(effective, Capability::READ);Sourcepub fn names(self) -> Vec<&'static str>
pub fn names(self) -> Vec<&'static str>
Returns a human-readable list of capability names.
§Example
use orcs_auth::Capability;
let caps = Capability::READ | Capability::WRITE;
let names = caps.names();
assert!(names.contains(&"READ"));
assert!(names.contains(&"WRITE"));Sourcepub fn parse(name: &str) -> Option<Capability>
pub fn parse(name: &str) -> Option<Capability>
Parses a capability name string (case-insensitive).
Unlike Flags::from_name (exact match), this accepts
lowercase input and aliases like “EXEC” for “EXECUTE”.
§Example
use orcs_auth::Capability;
assert_eq!(Capability::parse("read"), Some(Capability::READ));
assert_eq!(Capability::parse("EXECUTE"), Some(Capability::EXECUTE));
assert_eq!(Capability::parse("exec"), Some(Capability::EXECUTE));
assert_eq!(Capability::parse("http"), Some(Capability::HTTP));
assert_eq!(Capability::parse("unknown"), None);Sourcepub fn parse_list<'a>(names: &[&'a str]) -> (Capability, Vec<&'a str>)
pub fn parse_list<'a>(names: &[&'a str]) -> (Capability, Vec<&'a str>)
Parses a list of capability names into a combined set.
Returns the combined capabilities and a list of unknown names. Callers should decide how to handle unknown names (error, warn, etc.)
§Example
use orcs_auth::Capability;
let (caps, unknown) = Capability::parse_list(&["READ", "WRITE"]);
assert_eq!(caps, Capability::READ | Capability::WRITE);
assert!(unknown.is_empty());
let (caps, unknown) = Capability::parse_list(&["READ", "bad"]);
assert_eq!(caps, Capability::READ);
assert_eq!(unknown, vec!["bad"]);Trait Implementations§
Source§impl Binary for Capability
impl Binary for Capability
Source§impl BitAnd for Capability
impl BitAnd for Capability
Source§fn bitand(self, other: Capability) -> Capability
fn bitand(self, other: Capability) -> Capability
The bitwise and (&) of the bits in two flags values.
Source§type Output = Capability
type Output = Capability
& operator.Source§impl BitAndAssign for Capability
impl BitAndAssign for Capability
Source§fn bitand_assign(&mut self, other: Capability)
fn bitand_assign(&mut self, other: Capability)
The bitwise and (&) of the bits in two flags values.
Source§impl BitOr for Capability
impl BitOr for Capability
Source§fn bitor(self, other: Capability) -> Capability
fn bitor(self, other: Capability) -> Capability
The bitwise or (|) of the bits in two flags values.
Source§type Output = Capability
type Output = Capability
| operator.Source§impl BitOrAssign for Capability
impl BitOrAssign for Capability
Source§fn bitor_assign(&mut self, other: Capability)
fn bitor_assign(&mut self, other: Capability)
The bitwise or (|) of the bits in two flags values.
Source§impl BitXor for Capability
impl BitXor for Capability
Source§fn bitxor(self, other: Capability) -> Capability
fn bitxor(self, other: Capability) -> Capability
The bitwise exclusive-or (^) of the bits in two flags values.
Source§type Output = Capability
type Output = Capability
^ operator.Source§impl BitXorAssign for Capability
impl BitXorAssign for Capability
Source§fn bitxor_assign(&mut self, other: Capability)
fn bitxor_assign(&mut self, other: Capability)
The bitwise exclusive-or (^) of the bits in two flags values.
Source§impl Clone for Capability
impl Clone for Capability
Source§fn clone(&self) -> Capability
fn clone(&self) -> Capability
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Capability
impl Debug for Capability
Source§impl<'de> Deserialize<'de> for Capability
impl<'de> Deserialize<'de> for Capability
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Capability, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Capability, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for Capability
impl Display for Capability
Source§impl Extend<Capability> for Capability
impl Extend<Capability> for Capability
Source§fn extend<T>(&mut self, iterator: T)where
T: IntoIterator<Item = Capability>,
fn extend<T>(&mut self, iterator: T)where
T: IntoIterator<Item = Capability>,
The bitwise or (|) of the bits in each flags value.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Flags for Capability
impl Flags for Capability
Source§const FLAGS: &'static [Flag<Capability>]
const FLAGS: &'static [Flag<Capability>]
Source§fn from_bits_retain(bits: u16) -> Capability
fn from_bits_retain(bits: u16) -> Capability
Source§fn contains_unknown_bits(&self) -> bool
fn contains_unknown_bits(&self) -> bool
true if any unknown bits are set.Source§fn from_bits_truncate(bits: Self::Bits) -> Self
fn from_bits_truncate(bits: Self::Bits) -> Self
Source§fn from_name(name: &str) -> Option<Self>
fn from_name(name: &str) -> Option<Self>
Source§fn iter_names(&self) -> IterNames<Self>
fn iter_names(&self) -> IterNames<Self>
Source§fn iter_defined_names() -> IterDefinedNames<Self>
fn iter_defined_names() -> IterDefinedNames<Self>
Self::FLAGS.Source§fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn contains(&self, other: Self) -> boolwhere
Self: Sized,
fn contains(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn insert(&mut self, other: Self)where
Self: Sized,
fn insert(&mut self, other: Self)where
Self: Sized,
|) of the bits in two flags values.Source§fn remove(&mut self, other: Self)where
Self: Sized,
fn remove(&mut self, other: Self)where
Self: Sized,
&!). Read moreSource§fn toggle(&mut self, other: Self)where
Self: Sized,
fn toggle(&mut self, other: Self)where
Self: Sized,
^) of the bits in two flags values.Source§fn intersection(self, other: Self) -> Self
fn intersection(self, other: Self) -> Self
&) of the bits in two flags values.Source§fn difference(self, other: Self) -> Self
fn difference(self, other: Self) -> Self
&!). Read moreSource§fn symmetric_difference(self, other: Self) -> Self
fn symmetric_difference(self, other: Self) -> Self
^) of the bits in two flags values.Source§fn complement(self) -> Self
fn complement(self) -> Self
!) of the bits in a flags value, truncating the result.Source§impl FromIterator<Capability> for Capability
impl FromIterator<Capability> for Capability
Source§fn from_iter<T>(iterator: T) -> Capabilitywhere
T: IntoIterator<Item = Capability>,
fn from_iter<T>(iterator: T) -> Capabilitywhere
T: IntoIterator<Item = Capability>,
The bitwise or (|) of the bits in each flags value.
Source§impl Hash for Capability
impl Hash for Capability
Source§impl IntoIterator for Capability
impl IntoIterator for Capability
Source§type Item = Capability
type Item = Capability
Source§type IntoIter = Iter<Capability>
type IntoIter = Iter<Capability>
Source§fn into_iter(self) -> <Capability as IntoIterator>::IntoIter
fn into_iter(self) -> <Capability as IntoIterator>::IntoIter
Source§impl LowerHex for Capability
impl LowerHex for Capability
Source§impl Not for Capability
impl Not for Capability
Source§fn not(self) -> Capability
fn not(self) -> Capability
The bitwise negation (!) of the bits in a flags value, truncating the result.
Source§type Output = Capability
type Output = Capability
! operator.Source§impl Octal for Capability
impl Octal for Capability
Source§impl PartialEq for Capability
impl PartialEq for Capability
Source§impl Serialize for Capability
impl Serialize for Capability
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl Sub for Capability
impl Sub for Capability
Source§fn sub(self, other: Capability) -> Capability
fn sub(self, other: Capability) -> Capability
The intersection of a source flags value with the complement of a target flags value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.
Source§type Output = Capability
type Output = Capability
- operator.Source§impl SubAssign for Capability
impl SubAssign for Capability
Source§fn sub_assign(&mut self, other: Capability)
fn sub_assign(&mut self, other: Capability)
The intersection of a source flags value with the complement of a target flags value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.