pub struct Entities { /* private fields */ }
Expand description
Represents an entity hierarchy, and allows looking up Entity
objects by
UID.
Note that Entities
is not Serialize
itself – use either the
from_json_*()
and write_to_json()
methods here, or the proto
module in
cedar-policy
, which is capable of ser/de both Core types like this and
cedar-policy
types.
Implementations§
Source§impl Entities
impl Entities
Sourcepub fn is_partial(&self) -> bool
pub fn is_partial(&self) -> bool
Is this a partial store (created with .partial()
)
Sourcepub fn entity(&self, uid: &EntityUID) -> Dereference<'_, Entity>
pub fn entity(&self, uid: &EntityUID) -> Dereference<'_, Entity>
Get the Entity
with the given UID, if any
Sourcepub fn add_entities(
self,
collection: impl IntoIterator<Item = Arc<Entity>>,
schema: Option<&impl Schema>,
tc_computation: TCComputation,
extensions: &Extensions<'_>,
) -> Result<Self>
pub fn add_entities( self, collection: impl IntoIterator<Item = Arc<Entity>>, schema: Option<&impl Schema>, tc_computation: TCComputation, extensions: &Extensions<'_>, ) -> Result<Self>
Adds the crate::ast::Entity
s in the iterator to this Entities
.
Fails if
- there is a pair of non-identical entities in the passed iterator with the same Entity UID, or
- there is an entity in the passed iterator with the same Entity UID as a non-identical entity in this structure, or
- any error is encountered in the transitive closure computation.
If schema
is present, then the added entities will be validated
against the schema
, returning an error if they do not conform to the
schema.
(This method will not add action entities from the schema
.)
If you pass TCComputation::AssumeAlreadyComputed
, then the caller is
responsible for ensuring that TC and DAG hold before calling this method.
Sourcepub fn remove_entities(
self,
collection: impl IntoIterator<Item = EntityUID>,
tc_computation: TCComputation,
) -> Result<Self>
pub fn remove_entities( self, collection: impl IntoIterator<Item = EntityUID>, tc_computation: TCComputation, ) -> Result<Self>
Removes the crate::ast::EntityUID
s in the interator from this Entities
Fails if any error is encountered in the transitive closure computation.
If you pass TCComputation::AssumeAlreadyComputed
, then the caller is
responsible for ensuring that TC and DAG hold before calling this method
Sourcepub fn upsert_entities(
self,
collection: impl IntoIterator<Item = Arc<Entity>>,
schema: Option<&impl Schema>,
tc_computation: TCComputation,
extensions: &Extensions<'_>,
) -> Result<Self>
pub fn upsert_entities( self, collection: impl IntoIterator<Item = Arc<Entity>>, schema: Option<&impl Schema>, tc_computation: TCComputation, extensions: &Extensions<'_>, ) -> Result<Self>
Adds the crate::ast::Entity
s in the iterator to this Entities
.
Fails if any error is encountered in the transitive closure computation.
When a duplicate is encountered, the value is overwritten by the latest version.
If schema
is present, then the added entities will be validated
against the schema
, returning an error if they do not conform to the
schema.
(This method will not add action entities from the schema
.)
If you pass TCComputation::AssumeAlreadyComputed
, then the caller is
responsible for ensuring that TC and DAG hold before calling this method.
Sourcepub fn from_entities(
entities: impl IntoIterator<Item = Entity>,
schema: Option<&impl Schema>,
tc_computation: TCComputation,
extensions: &Extensions<'_>,
) -> Result<Self>
pub fn from_entities( entities: impl IntoIterator<Item = Entity>, schema: Option<&impl Schema>, tc_computation: TCComputation, extensions: &Extensions<'_>, ) -> Result<Self>
Create an Entities
object with the given entities.
If schema
is present, then action entities from that schema will also
be added to the Entities
.
Also, the entities in entities
will be validated against the schema
,
returning an error if they do not conform to the schema.
If you pass TCComputation::AssumeAlreadyComputed
, then the caller is
responsible for ensuring that TC and DAG hold before calling this method.
§Errors
EntitiesError::Duplicate
if there is a pair of non-identical entities inentities
with the same Entity UID, or there is an entity inentities
with the same Entity UID as a non-identical entity in this structureEntitiesError::TransitiveClosureError
iftc_computation == TCComputation::EnforceAlreadyComputed
and the entities are not transitively closedEntitiesError::InvalidEntity
ifschema
is not none and any entities do not conform to the schema
Sourcepub fn to_json_value(&self) -> Result<Value>
pub fn to_json_value(&self) -> Result<Value>
Convert an Entities
object into a JSON value suitable for parsing in
via EntityJsonParser
.
The returned JSON value will be parse-able even with no Schema
.
To parse an Entities
object from a JSON value, use EntityJsonParser
.
Sourcepub fn write_to_json(&self, f: impl Write) -> Result<()>
pub fn write_to_json(&self, f: impl Write) -> Result<()>
Dump an Entities
object into an entities JSON file.
The resulting JSON will be suitable for parsing in via
EntityJsonParser
, and will be parse-able even with no Schema
.
To read an Entities
object from an entities JSON file, use
EntityJsonParser
.
Sourcepub fn to_dot_str(&self, f: &mut impl Write) -> Result
pub fn to_dot_str(&self, f: &mut impl Write) -> Result
Write entities into a DOT graph. This function only returns an Err
result on a failing write!
to f
, so it is infallible if the Write
implementation cannot fail (e.g., 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