Struct cedar_policy::EntityUid
source · pub struct EntityUid(/* private fields */);Expand description
Unique Id for an entity, such as User::"alice"
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
use cedar_policy::{Entity, EntityId, EntityTypeName, EntityUid};
use std::str::FromStr;
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
use cedar_policy::{Entity, EntityId, EntityTypeName, EntityUid};
use std::str::FromStr;
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
use cedar_policy::{Entity, EntityId, EntityTypeName, EntityUid};
use std::str::FromStr;
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);
assert_eq!(euid.type_name(), &EntityTypeName::from_str("User").unwrap());
assert_eq!(euid.id(), &EntityId::from_str("alice").unwrap());
sourcepub fn from_json(json: Value) -> Result<Self, impl Error>
pub fn from_json(json: Value) -> Result<Self, impl Error>
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();
assert_eq!(euid.type_name(), &EntityTypeName::from_str("User").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:
use cedar_policy::EntityUid;
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
§type Err = ParseErrors
type Err = ParseErrors
source§impl Ord for EntityUid
impl Ord for EntityUid
source§impl PartialEq for EntityUid
impl PartialEq for EntityUid
source§impl PartialOrd for EntityUid
impl PartialOrd for EntityUid
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for EntityUid
impl StructuralEq for EntityUid
impl StructuralPartialEq for EntityUid
Auto Trait Implementations§
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
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§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
§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.