pub struct Entity {
pub id: EntityId,
pub label: String,
pub properties: HashMap<String, Value>,
}Expand description
A node in the knowledge graph.
Fields§
§id: EntityIdUnique identifier.
label: StringHuman-readable label (e.g. “Person”, “Concept”).
properties: HashMap<String, Value>Arbitrary key-value properties.
Implementations§
Source§impl Entity
impl Entity
Sourcepub fn new(id: impl Into<String>, label: impl Into<String>) -> Self
pub fn new(id: impl Into<String>, label: impl Into<String>) -> Self
Construct a new entity with no properties.
Sourcepub fn with_properties(
id: impl Into<String>,
label: impl Into<String>,
properties: HashMap<String, Value>,
) -> Self
pub fn with_properties( id: impl Into<String>, label: impl Into<String>, properties: HashMap<String, Value>, ) -> Self
Construct a new entity with the given properties.
Sourcepub fn with_property(self, key: impl Into<String>, value: Value) -> Self
pub fn with_property(self, key: impl Into<String>, value: Value) -> Self
Add a single key-value property, consuming and returning self.
Allows fluent builder-style construction:
let e = Entity::new("alice", "Person")
.with_property("age", 30.into())
.with_property("role", "engineer".into());Sourcepub fn has_property(&self, key: &str) -> bool
pub fn has_property(&self, key: &str) -> bool
Return true if the entity has a property with the given key.
Sourcepub fn property_value(&self, key: &str) -> Option<&Value>
pub fn property_value(&self, key: &str) -> Option<&Value>
Return a reference to the property value for key, or None if absent.
Sourcepub fn remove_property(&mut self, key: &str) -> Option<Value>
pub fn remove_property(&mut self, key: &str) -> Option<Value>
Remove the property with the given key, returning its previous value.
Returns None if the key was not present. Allows incremental
property pruning without needing to reconstruct the entire entity.
Sourcepub fn property_count(&self) -> usize
pub fn property_count(&self) -> usize
Return the number of properties stored on this entity.
Sourcepub fn properties_is_empty(&self) -> bool
pub fn properties_is_empty(&self) -> bool
Return true if this entity has no properties.
Sourcepub fn property_keys(&self) -> Vec<&str>
pub fn property_keys(&self) -> Vec<&str>
Return a sorted list of property keys for this entity.
Useful for inspecting an entity’s schema without cloning all values.