#[non_exhaustive]pub enum Principal {
User {
uid: PrincipalId,
attrs: IndexMap<String, Value>,
},
Agent {
uid: PrincipalId,
parent_uid: Option<PrincipalId>,
attrs: IndexMap<String, Value>,
},
}Expand description
A principal is either a User (human) or an Agent (AI). Both become
Cedar entities of type User or Agent.
§Construction
Use Principal::user, Principal::agent, Principal::subagent,
or Principal::with_attr — never construct the enum variants
directly. The variant fields are public only because serde
deserializes into them; treating them as a stable public API is
unsupported. #[non_exhaustive] keeps external matches safe.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
User
A human user.
Invariant: parent_uid is meaningless here; Cedar policies
should not branch on a User’s parent.
Agent
An AI agent, optionally with a parent (sub-agent pattern).
Implementations§
Source§impl Principal
impl Principal
Sourcepub fn user(uid: impl Into<PrincipalId>) -> Self
pub fn user(uid: impl Into<PrincipalId>) -> Self
Construct a User principal with the given UID.
§Examples
use agentguard_core::Principal;
let p = Principal::user("alice");
assert_eq!(p.entity_uid(), "User::\"alice\"");Sourcepub fn agent(uid: impl Into<PrincipalId>) -> Self
pub fn agent(uid: impl Into<PrincipalId>) -> Self
Construct an Agent principal with the given UID and no parent.
§Examples
use agentguard_core::Principal;
let p = Principal::agent("email-bot");
assert_eq!(p.entity_type(), "Agent");Sourcepub fn subagent(
uid: impl Into<PrincipalId>,
parent: impl Into<PrincipalId>,
) -> Self
pub fn subagent( uid: impl Into<PrincipalId>, parent: impl Into<PrincipalId>, ) -> Self
Construct a sub-agent whose parent is another agent.
§Examples
use agentguard_core::Principal;
let p = Principal::subagent("summarizer", "research");
assert_eq!(p.entity_uid(), "Agent::\"summarizer\"");Sourcepub fn with_attr(self, k: impl Into<String>, v: impl Into<Value>) -> Self
pub fn with_attr(self, k: impl Into<String>, v: impl Into<Value>) -> Self
Add an attribute and return self for chaining.
Sourcepub fn entity_type(&self) -> &'static str
pub fn entity_type(&self) -> &'static str
Cedar entity type name (User or Agent).
Sourcepub fn entity_uid(&self) -> String
👎Deprecated since 0.2.1: Use the Display impl to write into an existing buffer (no allocation).
pub fn entity_uid(&self) -> String
Full Cedar entity UID like User::"alice".
Prefer the Display impl for formatting into
an existing buffer (avoids a String allocation on the hot path).
This method is retained for callers that genuinely need an owned
String (e.g. serialization to JSON via serde_json::json!).
Sourcepub fn id(&self) -> &PrincipalId
pub fn id(&self) -> &PrincipalId
The principal’s UID without the type prefix.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Principal
impl<'de> Deserialize<'de> for Principal
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Principal
impl StructuralPartialEq for Principal
Auto Trait Implementations§
impl Freeze for Principal
impl RefUnwindSafe for Principal
impl Send for Principal
impl Sync for Principal
impl Unpin for Principal
impl UnwindSafe for Principal
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more