pub struct EntityUid(/* private fields */);
Expand description
Unique id for an entity, such as User::"alice"
.
An EntityUid
contains an EntityTypeName
and EntityId
. It can
be constructed from these components using
EntityUid::from_type_name_and_id
, parsed from a string using .parse()
(via EntityUid::from_str
), or constructed from a JSON value using
EntityUid::from_json
.
Implementations§
Source§impl EntityUid
impl EntityUid
Sourcepub fn type_name(&self) -> &EntityTypeName
pub fn type_name(&self) -> &EntityTypeName
Returns the portion of the Euid that represents namespace and entity type
let json_data = serde_json::json!({ "__entity": { "type": "User", "id": "alice" } });
let euid = EntityUid::from_json(json_data).unwrap();
assert_eq!(euid.type_name(), &EntityTypeName::from_str("User").unwrap());
Sourcepub fn id(&self) -> &EntityId
pub fn id(&self) -> &EntityId
Returns the id portion of the Euid
let json_data = serde_json::json!({ "__entity": { "type": "User", "id": "alice" } });
let euid = EntityUid::from_json(json_data).unwrap();
assert_eq!(euid.id(), &EntityId::from_str("alice").unwrap());
Sourcepub fn from_type_name_and_id(name: EntityTypeName, id: EntityId) -> Self
pub fn from_type_name_and_id(name: EntityTypeName, id: EntityId) -> Self
Creates EntityUid
from EntityTypeName
and EntityId
let eid = EntityId::from_str("alice").unwrap();
let type_name: EntityTypeName = EntityTypeName::from_str("User").unwrap();
let euid = EntityUid::from_type_name_and_id(type_name, eid);
Sourcepub fn from_json(json: Value) -> Result<Self, JsonDeserializationError>
pub fn from_json(json: Value) -> Result<Self, JsonDeserializationError>
Creates EntityUid
from a JSON value, which should have
either the implicit or explicit __entity
form.
let json_data = serde_json::json!({ "__entity": { "type": "User", "id": "123abc" } });
let euid = EntityUid::from_json(json_data).unwrap();
Trait Implementations§
Source§impl FromStr for EntityUid
impl FromStr for EntityUid
Source§fn from_str(uid_str: &str) -> Result<Self, Self::Err>
fn from_str(uid_str: &str) -> Result<Self, Self::Err>
Parse an EntityUid
.
An EntityUid
consists of an EntityTypeName
followed by a quoted EntityId
.
The two are joined by a ::
.
For the formal grammar, see https://docs.cedarpolicy.com/policies/syntax-grammar.html#entity
Examples:
let euid: EntityUid = r#"Foo::Bar::"george""#.parse().unwrap();
// Get the type of this euid (`Foo::Bar`)
euid.type_name();
// Or the id
euid.id();
This FromStr
implementation requires the normalized representation of the
UID. See https://github.com/cedar-policy/rfcs/pull/9/.
A note on safety:
DO NOT create EntityUid
’s via string concatenation.
If you have separate components of an EntityUid
, use EntityUid::from_type_name_and_id
Source§type Err = ParseErrors
type Err = ParseErrors
Source§impl Ord for EntityUid
impl Ord for EntityUid
Source§impl PartialOrd for EntityUid
impl PartialOrd for EntityUid
impl Eq for EntityUid
impl StructuralPartialEq for EntityUid
Auto Trait Implementations§
impl Freeze for EntityUid
impl RefUnwindSafe for EntityUid
impl Send for EntityUid
impl Sync for EntityUid
impl Unpin for EntityUid
impl UnwindSafe for EntityUid
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,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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