pub struct Entity { /* private fields */ }
Expand description
Entity datatype
Implementations§
Source§impl Entity
impl Entity
Sourcepub fn new(
uid: EntityUID,
attrs: impl IntoIterator<Item = (SmolStr, RestrictedExpr)>,
indirect_ancestors: HashSet<EntityUID>,
parents: HashSet<EntityUID>,
tags: impl IntoIterator<Item = (SmolStr, RestrictedExpr)>,
extensions: &Extensions<'_>,
) -> Result<Self, EntityAttrEvaluationError>
pub fn new( uid: EntityUID, attrs: impl IntoIterator<Item = (SmolStr, RestrictedExpr)>, indirect_ancestors: HashSet<EntityUID>, parents: HashSet<EntityUID>, tags: impl IntoIterator<Item = (SmolStr, RestrictedExpr)>, extensions: &Extensions<'_>, ) -> Result<Self, EntityAttrEvaluationError>
Create a new Entity
with this UID, attributes, ancestors, and tags
§Errors
- Will error if any of the [
RestrictedExpr]
s inattrs
ortags
error when evaluated
Sourcepub fn new_with_attr_partial_value(
uid: EntityUID,
attrs: impl IntoIterator<Item = (SmolStr, PartialValue)>,
indirect_ancestors: HashSet<EntityUID>,
parents: HashSet<EntityUID>,
tags: impl IntoIterator<Item = (SmolStr, PartialValue)>,
) -> Self
pub fn new_with_attr_partial_value( uid: EntityUID, attrs: impl IntoIterator<Item = (SmolStr, PartialValue)>, indirect_ancestors: HashSet<EntityUID>, parents: HashSet<EntityUID>, tags: impl IntoIterator<Item = (SmolStr, PartialValue)>, ) -> Self
Create a new Entity
with this UID, attributes, ancestors, and tags
Unlike in Entity::new()
, in this constructor, attributes and tags are
expressed as PartialValue
.
Callers should consider directly using [Entity::new_with_attr_partial_value_serialized_as_expr
]
if they would call this method by first building a map, as it will
deconstruct and re-build the map perhaps unnecessarily.
Sourcepub fn get(&self, attr: &str) -> Option<&PartialValue>
pub fn get(&self, attr: &str) -> Option<&PartialValue>
Get the value for the given attribute, or None
if not present
Sourcepub fn get_tag(&self, tag: &str) -> Option<&PartialValue>
pub fn get_tag(&self, tag: &str) -> Option<&PartialValue>
Get the value for the given tag, or None
if not present
Sourcepub fn is_descendant_of(&self, e: &EntityUID) -> bool
pub fn is_descendant_of(&self, e: &EntityUID) -> bool
Is this Entity
a (direct or indirect) descendant of e
in the entity hierarchy?
Sourcepub fn is_indirect_descendant_of(&self, e: &EntityUID) -> bool
pub fn is_indirect_descendant_of(&self, e: &EntityUID) -> bool
Is this Entity
a an indirect descendant of e
in the entity hierarchy?
Sourcepub fn is_child_of(&self, e: &EntityUID) -> bool
pub fn is_child_of(&self, e: &EntityUID) -> bool
Is this Entity
a direct decendant (child) of e
in the entity hierarchy?
Sourcepub fn ancestors(&self) -> impl Iterator<Item = &EntityUID>
pub fn ancestors(&self) -> impl Iterator<Item = &EntityUID>
Iterate over this entity’s (direct or indirect) ancestors
Sourcepub fn indirect_ancestors(&self) -> impl Iterator<Item = &EntityUID>
pub fn indirect_ancestors(&self) -> impl Iterator<Item = &EntityUID>
Iterate over this entity’s indirect ancestors
Sourcepub fn parents(&self) -> impl Iterator<Item = &EntityUID>
pub fn parents(&self) -> impl Iterator<Item = &EntityUID>
Iterate over this entity’s direct ancestors (parents)
Get the number of tags on this entity
Sourcepub fn keys(&self) -> impl Iterator<Item = &SmolStr>
pub fn keys(&self) -> impl Iterator<Item = &SmolStr>
Iterate over this entity’s attribute names
Sourcepub fn attrs(&self) -> impl Iterator<Item = (&SmolStr, &PartialValue)>
pub fn attrs(&self) -> impl Iterator<Item = (&SmolStr, &PartialValue)>
Iterate over this entity’s attributes
Iterate over this entity’s tags
Sourcepub fn with_uid(uid: EntityUID) -> Self
pub fn with_uid(uid: EntityUID) -> Self
Create an Entity
with the given UID, no attributes, no parents, and no tags.
Sourcepub fn deep_eq(&self, other: &Self) -> bool
pub fn deep_eq(&self, other: &Self) -> bool
Test if two Entity
objects are deep/structurally equal.
That is, not only do they have the same UID, but also the same
attributes, attribute values, and ancestors/parents.
Does not test that they have the same direct parents, only that they have the same overall ancestor set.
Sourcepub fn add_indirect_ancestor(&mut self, uid: EntityUID)
pub fn add_indirect_ancestor(&mut self, uid: EntityUID)
Mark the given UID
as an indirect ancestor of this Entity
The given UID
will not be added as an indirecty ancestor if
it is already a direct ancestor (parent) of this Entity
The caller of this code is responsible for maintaining
transitive closure of hierarchy.
Sourcepub fn add_parent(&mut self, uid: EntityUID)
pub fn add_parent(&mut self, uid: EntityUID)
Mark the given UID
as a (direct) parent of this Entity
, and
remove the UID from indirect ancestors
if it was previously added as an indirect ancestor
The caller of this code is responsible for maintaining
transitive closure of hierarchy.
Sourcepub fn remove_indirect_ancestor(&mut self, uid: &EntityUID)
pub fn remove_indirect_ancestor(&mut self, uid: &EntityUID)
Remove the given UID
as an indirect ancestor of this Entity
.
No effect if the UID
is a direct parent.
The caller of this code is responsible for maintaining
transitive closure of hierarchy.
Sourcepub fn remove_parent(&mut self, uid: &EntityUID)
pub fn remove_parent(&mut self, uid: &EntityUID)
Remove the given UID
as a (direct) parent of this Entity
.
No effect on the Entity
’s indirect ancestors.
The caller of this code is responsible for maintaining
transitive closure of hierarchy.
Sourcepub fn remove_all_indirect_ancestors(&mut self)
pub fn remove_all_indirect_ancestors(&mut self)
Remove all indirect ancestors of this Entity
.
The caller of this code is responsible for maintaining transitive closure of hierarchy.
Sourcepub fn into_inner(
self,
) -> (EntityUID, HashMap<SmolStr, PartialValue>, HashSet<EntityUID>, HashSet<EntityUID>, HashMap<SmolStr, PartialValue>)
pub fn into_inner( self, ) -> (EntityUID, HashMap<SmolStr, PartialValue>, HashSet<EntityUID>, HashSet<EntityUID>, HashMap<SmolStr, PartialValue>)
Consume the entity and return the entity’s owned Uid, attributes, ancestors, parents, and tags.
Sourcepub fn write_to_json(&self, f: impl Write) -> Result<(), EntitiesError>
pub fn write_to_json(&self, f: impl Write) -> Result<(), EntitiesError>
Write the entity to a json document
Sourcepub fn to_json_value(&self) -> Result<Value, EntitiesError>
pub fn to_json_value(&self) -> Result<Value, EntitiesError>
write the entity to a json value
Sourcepub fn to_json_string(&self) -> Result<String, EntitiesError>
pub fn to_json_string(&self) -> Result<String, EntitiesError>
write the entity to a json string
Trait Implementations§
Source§impl TCNode<EntityUID> for Entity
impl TCNode<EntityUID> for Entity
Source§fn add_edge_to(&mut self, k: EntityUID)
fn add_edge_to(&mut self, k: EntityUID)
k
.Source§fn out_edges(&self) -> Box<dyn Iterator<Item = &EntityUID> + '_>
fn out_edges(&self) -> Box<dyn Iterator<Item = &EntityUID> + '_>
Source§fn has_edge_to(&self, e: &EntityUID) -> bool
fn has_edge_to(&self, e: &EntityUID) -> bool
k
.Source§fn reset_edges(&mut self)
fn reset_edges(&mut self)
impl Eq for Entity
Auto Trait Implementations§
impl Freeze for Entity
impl RefUnwindSafe for Entity
impl Send for Entity
impl Sync for Entity
impl Unpin for Entity
impl UnwindSafe for Entity
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