pub struct Entities(/* private fields */);Expand description
Represents an entity hierarchy, and allows looking up Entity objects by
Uid.
Implementations§
Source§impl Entities
impl Entities
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create a fresh Entities with no entities
let entities = Entities::empty();Sourcepub fn get(&self, uid: &EntityUid) -> Option<&Entity>
pub fn get(&self, uid: &EntityUid) -> Option<&Entity>
Get the Entity with the given Uid, if any
Sourcepub fn partial(self) -> Self
Available on crate feature partial-eval only.
pub fn partial(self) -> Self
partial-eval only.Transform the store into a partial store, where
attempting to dereference a non-existent EntityUid results in
a residual instead of an error.
Sourcepub fn deep_eq(&self, other: &Self) -> bool
pub fn deep_eq(&self, other: &Self) -> bool
Test if two entity hierarchies are structurally equal. The hierarchies
must contain the same set of entity ids, and the entities with each id
must be structurally equal (decided by Entity::deep_eq). Ancestor
equality between entities is always decided by comparing the transitive
closure of ancestor and not direct parents.
Sourcepub fn from_entities(
entities: impl IntoIterator<Item = Entity>,
schema: Option<&Schema>,
) -> Result<Self, EntitiesError>
pub fn from_entities( entities: impl IntoIterator<Item = Entity>, schema: Option<&Schema>, ) -> Result<Self, EntitiesError>
Create an Entities object with the given entities.
schema represents a source of Action entities, which will be added
to the entities provided.
(If any Action entities are present in the provided entities, and a
schema is also provided, each Action entity in the provided entities
must exactly match its definition in the schema or an error is
returned.)
If a schema is present, this function will also ensure that the
produced entities fully conform to the schema – for instance, it will
error if attributes have the wrong types (e.g., string instead of
integer), or if required attributes are missing or superfluous
attributes are provided.
§Errors
EntitiesError::Duplicateif there are any duplicate entities inentitiesEntitiesError::InvalidEntityifschemais not none and any entities do not conform to the schema
Sourcepub fn add_entities(
self,
entities: impl IntoIterator<Item = Entity>,
schema: Option<&Schema>,
) -> Result<Self, EntitiesError>
pub fn add_entities( self, entities: impl IntoIterator<Item = Entity>, schema: Option<&Schema>, ) -> Result<Self, EntitiesError>
Add all of the Entitys in the collection to this Entities
structure, re-computing the transitive closure.
If a schema is provided, this method will ensure that the added
entities fully conform to the schema – for instance, it will error if
attributes have the wrong types (e.g., string instead of integer), or if
required attributes are missing or superfluous attributes are provided.
(This method will not add action entities from the schema.)
Re-computing the transitive closure can be expensive, so it is advised to not call this method in a loop.
§Errors
EntitiesError::Duplicateif there is a pair of non-identical entities inentitieswith the same Entity UID, or there is an entity inentitieswith the same Entity UID as a non-identical entity in this structureEntitiesError::InvalidEntityifschemais not none and any entities do not conform to the schema
Sourcepub fn remove_entities(
self,
entity_ids: impl IntoIterator<Item = EntityUid>,
) -> Result<Self, EntitiesError>
pub fn remove_entities( self, entity_ids: impl IntoIterator<Item = EntityUid>, ) -> Result<Self, EntitiesError>
Sourcepub fn upsert_entities(
self,
entities: impl IntoIterator<Item = Entity>,
schema: Option<&Schema>,
) -> Result<Self, EntitiesError>
pub fn upsert_entities( self, entities: impl IntoIterator<Item = Entity>, schema: Option<&Schema>, ) -> Result<Self, EntitiesError>
Updates or adds all of the Entitys in the collection to this Entities
structure, re-computing the transitive closure.
If a schema is provided, this method will ensure that the added
entities fully conform to the schema – for instance, it will error if
attributes have the wrong types (e.g., string instead of integer), or if
required attributes are missing or superfluous attributes are provided.
(This method will not add action entities from the schema.)
Re-computing the transitive closure can be expensive, so it is advised to not call this method in a loop.
§Errors
EntitiesError::InvalidEntityifschemais not none and any entities do not conform to the schema
Sourcepub fn add_entities_from_json_str(
self,
json: &str,
schema: Option<&Schema>,
) -> Result<Self, EntitiesError>
pub fn add_entities_from_json_str( self, json: &str, schema: Option<&Schema>, ) -> Result<Self, EntitiesError>
Parse an entities JSON file (in &str form) and add them into this
Entities structure, re-computing the transitive closure
If a schema is provided, this will inform the parsing: for instance, it
will allow __entity and __extn escapes to be implicit.
This method will also ensure that the added entities fully conform to the
schema – for instance, it will error if attributes have the wrong types
(e.g., string instead of integer), or if required attributes are missing
or superfluous attributes are provided.
(This method will not add action entities from the schema.)
Re-computing the transitive closure can be expensive, so it is advised to not call this method in a loop.
§Errors
EntitiesError::Duplicateif there is a pair of non-identical entities inentitieswith the same Entity UID, or there is an entity inentitieswith the same Entity UID as a non-identical entity in this structureEntitiesError::InvalidEntityifschemais not none and any entities do not conform to the schemaEntitiesError::Deserializationif there are errors while parsing the json
Sourcepub fn add_entities_from_json_value(
self,
json: Value,
schema: Option<&Schema>,
) -> Result<Self, EntitiesError>
pub fn add_entities_from_json_value( self, json: Value, schema: Option<&Schema>, ) -> Result<Self, EntitiesError>
Parse an entities JSON file (in serde_json::Value form) and add them
into this Entities structure, re-computing the transitive closure
If a schema is provided, this will inform the parsing: for instance, it
will allow __entity and __extn escapes to be implicit.
This method will also ensure that the added entities fully conform to the
schema – for instance, it will error if attributes have the wrong types
(e.g., string instead of integer), or if required attributes are missing
or superfluous attributes are provided.
(This method will not add action entities from the schema.)
Re-computing the transitive closure can be expensive, so it is advised to not call this method in a loop.
§Errors
EntitiesError::Duplicateif there is a pair of non-identical entities inentitieswith the same Entity UID, or there is an entity inentitieswith the same Entity UID as a non-identical entity in this structureEntitiesError::InvalidEntityifschemais not none and any entities do not conform to the schemaEntitiesError::Deserializationif there are errors while parsing the json
Sourcepub fn add_entities_from_json_file(
self,
json: impl Read,
schema: Option<&Schema>,
) -> Result<Self, EntitiesError>
pub fn add_entities_from_json_file( self, json: impl Read, schema: Option<&Schema>, ) -> Result<Self, EntitiesError>
Parse an entities JSON file (in std::io::Read form) and add them
into this Entities structure, re-computing the transitive closure
If a schema is provided, this will inform the parsing: for instance, it
will allow __entity and __extn escapes to be implicit.
This method will also ensure that the added entities fully conform to the
schema – for instance, it will error if attributes have the wrong types
(e.g., string instead of integer), or if required attributes are missing
or superfluous attributes are provided.
(This method will not add action entities from the schema.)
Re-computing the transitive closure can be expensive, so it is advised to not call this method in a loop.
§Errors
EntitiesError::Duplicateif there is a pair of non-identical entities inentitieswith the same Entity UID, or there is an entity inentitieswith the same Entity UID as a non-identical entity in this structureEntitiesError::InvalidEntityifschemais not none and any entities do not conform to the schemaEntitiesError::Deserializationif there are errors while parsing the json
Sourcepub fn from_json_str(
json: &str,
schema: Option<&Schema>,
) -> Result<Self, EntitiesError>
pub fn from_json_str( json: &str, schema: Option<&Schema>, ) -> Result<Self, EntitiesError>
Parse an entities JSON file (in &str form) into an Entities object
schema represents a source of Action entities, which will be added
to the entities parsed from JSON.
(If any Action entities are present in the JSON, and a schema is
also provided, each Action entity in the JSON must exactly match its
definition in the schema or an error is returned.)
If a schema is present, this will also inform the parsing: for
instance, it will allow __entity and __extn escapes to be implicit.
Finally, if a schema is present, this function will ensure
that the produced entities fully conform to the schema – for
instance, it will error if attributes have the wrong types (e.g., string
instead of integer), or if required attributes are missing or
superfluous attributes are provided.
§Errors
EntitiesError::Duplicateif there are any duplicate entities inentitiesEntitiesError::InvalidEntityifschemais not none and any entities do not conform to the schemaEntitiesError::Deserializationif there are errors while parsing the json
let data =r#"
[
{
"uid": {"type":"User","id":"alice"},
"attrs": {
"age":19,
"ip_addr":{"__extn":{"fn":"ip", "arg":"10.0.1.101"}}
},
"parents": [{"type":"Group","id":"admin"}]
},
{
"uid": {"type":"Group","id":"admin"},
"attrs": {},
"parents": []
}
]
"#;
let entities = Entities::from_json_str(data, None).unwrap();Sourcepub fn from_json_value(
json: Value,
schema: Option<&Schema>,
) -> Result<Self, EntitiesError>
pub fn from_json_value( json: Value, schema: Option<&Schema>, ) -> Result<Self, EntitiesError>
Parse an entities JSON file (in serde_json::Value form) into an
Entities object
schema represents a source of Action entities, which will be added
to the entities parsed from JSON.
(If any Action entities are present in the JSON, and a schema is
also provided, each Action entity in the JSON must exactly match its
definition in the schema or an error is returned.)
If a schema is present, this will also inform the parsing: for
instance, it will allow __entity and __extn escapes to be implicit.
Finally, if a schema is present, this function will ensure
that the produced entities fully conform to the schema – for
instance, it will error if attributes have the wrong types (e.g., string
instead of integer), or if required attributes are missing or
superfluous attributes are provided.
§Errors
EntitiesError::Duplicateif there are any duplicate entities inentitiesEntitiesError::InvalidEntityifschemais not none and any entities do not conform to the schemaEntitiesError::Deserializationif there are errors while parsing the json
let data =serde_json::json!(
[
{
"uid": {"type":"User","id":"alice"},
"attrs": {
"age":19,
"ip_addr":{"__extn":{"fn":"ip", "arg":"10.0.1.101"}}
},
"parents": [{"type":"Group","id":"admin"}]
},
{
"uid": {"type":"Group","id":"admin"},
"attrs": {},
"parents": []
}
]
);
let entities = Entities::from_json_value(data, None).unwrap();Sourcepub fn from_json_file(
json: impl Read,
schema: Option<&Schema>,
) -> Result<Self, EntitiesError>
pub fn from_json_file( json: impl Read, schema: Option<&Schema>, ) -> Result<Self, EntitiesError>
Parse an entities JSON file (in std::io::Read form) into an Entities
object
schema represents a source of Action entities, which will be added
to the entities parsed from JSON.
(If any Action entities are present in the JSON, and a schema is
also provided, each Action entity in the JSON must exactly match its
definition in the schema or an error is returned.)
If a schema is present, this will also inform the parsing: for
instance, it will allow __entity and __extn escapes to be implicit.
Finally, if a schema is present, this function will ensure
that the produced entities fully conform to the schema – for
instance, it will error if attributes have the wrong types (e.g., string
instead of integer), or if required attributes are missing or
superfluous attributes are provided.
§Errors
EntitiesError::Duplicateif there are any duplicate entities inentitiesEntitiesError::InvalidEntityifschemais not none and any entities do not conform to the schemaEntitiesError::Deserializationif there are errors while parsing the json
Sourcepub fn is_ancestor_of(&self, a: &EntityUid, b: &EntityUid) -> bool
pub fn is_ancestor_of(&self, a: &EntityUid, b: &EntityUid) -> bool
Is entity a an ancestor of entity b?
Same semantics as b in a in the Cedar language
Sourcepub fn ancestors<'a>(
&'a self,
euid: &EntityUid,
) -> Option<impl Iterator<Item = &'a EntityUid>>
pub fn ancestors<'a>( &'a self, euid: &EntityUid, ) -> Option<impl Iterator<Item = &'a EntityUid>>
Get an iterator over the ancestors of the given Euid.
Returns None if the given Euid does not exist.
Sourcepub fn write_to_json(&self, f: impl Write) -> Result<(), EntitiesError>
pub fn write_to_json(&self, f: impl Write) -> Result<(), EntitiesError>
Dump an Entities object into an entities JSON file.
The resulting JSON will be suitable for parsing in via
from_json_*, and will be parse-able even with no Schema.
To read an Entities object from an entities JSON file, use
from_json_file.
Sourcepub fn to_dot_str(&self) -> String
pub fn to_dot_str(&self) -> String
Trait Implementations§
Source§impl IntoIterator for Entities
impl IntoIterator for Entities
impl Eq for Entities
impl StructuralPartialEq for Entities
Auto Trait Implementations§
impl Freeze for Entities
impl RefUnwindSafe for Entities
impl Send for Entities
impl Sync for Entities
impl Unpin for Entities
impl UnwindSafe for Entities
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§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