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