Entity

Struct Entity 

Source
pub struct Entity { /* private fields */ }
Expand description

Entity datatype

Implementations§

Source§

impl Entity

Source

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 in attrs or tags error when evaluated
Source

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.

Source

pub fn uid(&self) -> &EntityUID

Get the UID of this entity

Source

pub fn get(&self, attr: &str) -> Option<&PartialValue>

Get the value for the given attribute, or None if not present

Source

pub fn get_tag(&self, tag: &str) -> Option<&PartialValue>

Get the value for the given tag, or None if not present

Source

pub fn is_descendant_of(&self, e: &EntityUID) -> bool

Is this Entity a (direct or indirect) descendant of e in the entity hierarchy?

Source

pub fn is_indirect_descendant_of(&self, e: &EntityUID) -> bool

Is this Entity a an indirect descendant of e in the entity hierarchy?

Source

pub fn is_child_of(&self, e: &EntityUID) -> bool

Is this Entity a direct decendant (child) of e in the entity hierarchy?

Source

pub fn ancestors(&self) -> impl Iterator<Item = &EntityUID>

Iterate over this entity’s (direct or indirect) ancestors

Source

pub fn indirect_ancestors(&self) -> impl Iterator<Item = &EntityUID>

Iterate over this entity’s indirect ancestors

Source

pub fn parents(&self) -> impl Iterator<Item = &EntityUID>

Iterate over this entity’s direct ancestors (parents)

Source

pub fn attrs_len(&self) -> usize

Get the number of attributes on this entity

Source

pub fn tags_len(&self) -> usize

Get the number of tags on this entity

Source

pub fn keys(&self) -> impl Iterator<Item = &SmolStr>

Iterate over this entity’s attribute names

Source

pub fn tag_keys(&self) -> impl Iterator<Item = &SmolStr>

Iterate over this entity’s tag names

Source

pub fn attrs(&self) -> impl Iterator<Item = (&SmolStr, &PartialValue)>

Iterate over this entity’s attributes

Source

pub fn tags(&self) -> impl Iterator<Item = (&SmolStr, &PartialValue)>

Iterate over this entity’s tags

Source

pub fn with_uid(uid: EntityUID) -> Self

Create an Entity with the given UID, no attributes, no parents, and no tags.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn write_to_json(&self, f: impl Write) -> Result<(), EntitiesError>

Write the entity to a json document

Source

pub fn to_json_value(&self) -> Result<Value, EntitiesError>

write the entity to a json value

Source

pub fn to_json_string(&self) -> Result<String, EntitiesError>

write the entity to a json string

Trait Implementations§

Source§

impl Clone for Entity

Source§

fn clone(&self) -> Entity

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Entity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Entity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Entity

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Entity

Entitys are equal if their UIDs are equal

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StaticallyTyped for Entity

Source§

fn type_of(&self) -> Type

Get the object’s type
Source§

impl TCNode<EntityUID> for Entity

Source§

fn get_key(&self) -> EntityUID

Extract a unique identifier for the node.
Source§

fn add_edge_to(&mut self, k: EntityUID)

Add an edge out off this node to the node with key k.
Source§

fn out_edges(&self) -> Box<dyn Iterator<Item = &EntityUID> + '_>

Retrieve an iterator for the edges out of this node.
Source§

fn has_edge_to(&self, e: &EntityUID) -> bool

Return true when their is an edge between this node and the node with key k.
Source§

fn reset_edges(&mut self)

Resets edges to base
Source§

fn direct_edges(&self) -> Box<dyn Iterator<Item = &EntityUID> + '_>

Retrieves an iterator for direct edges out of this node.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.