Entity

Struct Entity 

Source
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

Source

pub fn new(name: impl Into<String>) -> Self

👎Deprecated: use new_with_namespace instead

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");
Source

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");
Source

pub fn with_version(self, version: SemanticVersion) -> Self

Sets the entity version.

Source

pub fn with_replaces(self, replaces: String) -> Self

Sets the entity that this version replaces.

Source

pub fn with_changes(self, changes: Vec<String>) -> Self

Sets the list of changes in this version.

Source

pub fn version(&self) -> Option<&SemanticVersion>

Returns the entity version.

Source

pub fn replaces(&self) -> Option<&str>

Returns the entity that this version replaces.

Source

pub fn changes(&self) -> &[String]

Returns the list of changes in this version.

Source

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.

Source

pub fn id(&self) -> &ConceptId

Returns the entity’s unique identifier.

Source

pub fn name(&self) -> &str

Returns the entity’s name.

Source

pub fn namespace(&self) -> &str

Returns the entity’s namespace.

Source

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)));
Source

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);
Source

pub fn attributes(&self) -> &HashMap<String, Value>

Returns all attributes as a reference.

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<'de> Deserialize<'de> for Entity

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Entity

Source§

fn eq(&self, other: &Entity) -> 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 Serialize for Entity

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> 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<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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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, 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,