pub struct Entity { /* private fields */ }Expand description
Represents a business actor, location, or organizational unit.
Entities are the “WHO” in enterprise models - the actors that perform actions, hold resources, or participate in flows.
§Examples
Basic usage:
use sea_core::primitives::Entity;
let warehouse = Entity::new_with_namespace("Main Warehouse", "default");
assert_eq!(warehouse.name(), "Main Warehouse");
assert_eq!(warehouse.namespace(), "default");With namespace:
use sea_core::primitives::Entity;
let warehouse = Entity::new_with_namespace("Warehouse A", "logistics");
assert_eq!(warehouse.namespace(), "logistics");With custom attributes:
use sea_core::primitives::Entity;
use serde_json::json;
let mut factory = Entity::new_with_namespace("Factory", "default");
factory.set_attribute("capacity", json!(5000));
factory.set_attribute("location", json!("Building 3"));
assert_eq!(factory.get_attribute("capacity"), Some(&json!(5000)));Serialization:
use sea_core::primitives::Entity;
let entity = Entity::new_with_namespace("Test Entity", "default");
let json = serde_json::to_string(&entity).unwrap();
let deserialized: Entity = serde_json::from_str(&json).unwrap();
assert_eq!(entity.name(), deserialized.name());Implementations§
Source§impl Entity
impl Entity
Sourcepub fn new(name: impl Into<String>) -> Self
👎Deprecated: use new_with_namespace instead
pub fn new(name: impl Into<String>) -> Self
Creates a new Entity with a generated UUID (deprecated - use new_with_namespace).
§Examples
use sea_core::primitives::Entity;
let entity = Entity::new_with_namespace("Warehouse", "default");
assert_eq!(entity.name(), "Warehouse");Sourcepub fn new_with_namespace(
name: impl Into<String>,
namespace: impl Into<String>,
) -> Self
pub fn new_with_namespace( name: impl Into<String>, namespace: impl Into<String>, ) -> Self
Creates a new Entity with a specific namespace.
§Examples
use sea_core::primitives::Entity;
let entity = Entity::new_with_namespace("Warehouse", "logistics");
assert_eq!(entity.namespace(), "logistics");Sourcepub fn with_version(self, version: SemanticVersion) -> Self
pub fn with_version(self, version: SemanticVersion) -> Self
Sets the entity version.
Sourcepub fn with_replaces(self, replaces: String) -> Self
pub fn with_replaces(self, replaces: String) -> Self
Sets the entity that this version replaces.
Sourcepub fn with_changes(self, changes: Vec<String>) -> Self
pub fn with_changes(self, changes: Vec<String>) -> Self
Sets the list of changes in this version.
Sourcepub fn version(&self) -> Option<&SemanticVersion>
pub fn version(&self) -> Option<&SemanticVersion>
Returns the entity version.
Sourcepub fn from_legacy_uuid(
uuid: Uuid,
name: impl Into<String>,
namespace: impl Into<String>,
) -> Self
pub fn from_legacy_uuid( uuid: Uuid, name: impl Into<String>, namespace: impl Into<String>, ) -> Self
Creates an Entity from a legacy UUID for backward compatibility.
Sourcepub fn set_attribute(&mut self, key: impl Into<String>, value: Value)
pub fn set_attribute(&mut self, key: impl Into<String>, value: Value)
Sets a custom attribute.
§Examples
use sea_core::primitives::Entity;
use serde_json::json;
let mut entity = Entity::new_with_namespace("Factory", "default");
entity.set_attribute("capacity", json!(5000));
assert_eq!(entity.get_attribute("capacity"), Some(&json!(5000)));Sourcepub fn get_attribute(&self, key: &str) -> Option<&Value>
pub fn get_attribute(&self, key: &str) -> Option<&Value>
Gets a custom attribute.
Returns None if the attribute doesn’t exist.
§Examples
use sea_core::primitives::Entity;
use serde_json::json;
let mut entity = Entity::new_with_namespace("Factory", "default");
entity.set_attribute("capacity", json!(5000));
assert_eq!(entity.get_attribute("capacity"), Some(&json!(5000)));
assert_eq!(entity.get_attribute("missing"), None);Sourcepub fn attributes(&self) -> &HashMap<String, Value>
pub fn attributes(&self) -> &HashMap<String, Value>
Returns all attributes as a reference.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Entity
impl<'de> Deserialize<'de> for Entity
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq 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
Mutably borrows from an owned value. Read more