Object

Struct Object 

Source
pub struct Object {
    pub id: ObjectId,
    pub name: String,
    pub object_type: String,
    pub traits: HashMap<String, Trait>,
    pub metadata: HashMap<String, String>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}
Expand description

An object is an identity container that composes traits

Fields§

§id: ObjectId

Unique identifier for this object

§name: String

Name of the object

§object_type: String

Type of the object

§traits: HashMap<String, Trait>

Traits associated with this object

§metadata: HashMap<String, String>

Metadata about the object

§created_at: DateTime<Utc>

Creation timestamp

§updated_at: DateTime<Utc>

Last update timestamp

Implementations§

Source§

impl Object

Source

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

Create a new object with the given name and type

Source

pub fn with_traits( name: impl Into<String>, object_type: impl Into<String>, traits: Vec<Trait>, ) -> Self

Create a new object with initial traits

Source

pub fn with_capacity( name: impl Into<String>, object_type: impl Into<String>, trait_capacity: usize, metadata_capacity: usize, ) -> Self

Create a new object with pre-allocated capacity

Source

pub fn name(&self) -> &str

Get the object name

Source

pub fn object_type(&self) -> &str

Get the object type

Source

pub fn id(&self) -> ObjectId

Get the object ID

Source

pub fn add_trait(&mut self, trait_obj: Trait)

Add a trait to this object

Source

pub fn add_traits(&mut self, traits: impl IntoIterator<Item = Trait>)

Add multiple traits efficiently

Source

pub fn add_traits_bulk(&mut self, traits: impl IntoIterator<Item = Trait>)

Add multiple traits without timestamp updates (for bulk operations)

Source

pub fn add_trait_internal(&mut self, trait_obj: Trait)

Add a trait without timestamp update (for internal operations)

Source

pub fn remove_trait(&mut self, trait_name: &str) -> Option<Trait>

Remove a trait from this object

Source

pub fn get_trait(&self, trait_name: &str) -> Option<&Trait>

Get a trait by name

Source

pub fn get_trait_mut(&mut self, trait_name: &str) -> Option<&mut Trait>

Get a trait by name (mutable)

Source

pub fn get_trait_data(&self, trait_name: &str) -> Option<&TraitData>

Get trait data by name (zero-copy access)

Source

pub fn get_trait_data_mut(&mut self, trait_name: &str) -> Option<&mut TraitData>

Get trait data by name (mutable, zero-copy access)

Source

pub fn traits(&self) -> &HashMap<String, Trait>

Get all traits

Source

pub fn has_trait(&self, trait_name: &str) -> bool

Check if the object has a specific trait

Source

pub fn has_traits(&self, trait_names: &[&str]) -> bool

Check if the object has multiple traits (efficient batch check)

Source

pub fn has_any_traits(&self) -> bool

Check if the object has any traits

Source

pub fn get_metadata(&self, key: &str) -> Option<&String>

Get a metadata value

Source

pub fn set_metadata(&mut self, key: impl Into<String>, value: impl Into<String>)

Set a metadata value

Source

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

Get all metadata

Source

pub fn created_at(&self) -> DateTime<Utc>

Get the creation timestamp

Source

pub fn updated_at(&self) -> DateTime<Utc>

Get the last update timestamp

Source

pub fn trait_names(&self) -> Vec<&String>

Get trait names as a vector

Source

pub fn trait_ids(&self) -> Vec<TraitId>

Get trait IDs as a vector

Source

pub fn trait_count(&self) -> usize

Get the number of traits

Source

pub fn metadata_count(&self) -> usize

Get the number of metadata entries

Source

pub fn reserve_traits(&mut self, additional: usize)

Reserve capacity for traits

Source

pub fn reserve_metadata(&mut self, additional: usize)

Reserve capacity for metadata

Source

pub fn validate_required_traits( &self, required_traits: &[&str], ) -> Result<(), OatsError>

Validate that the object has required traits

Source

pub fn is_valid(&self) -> bool

Check if the object is valid (has required fields)

Trait Implementations§

Source§

impl Clone for Object

Source§

fn clone(&self) -> Object

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 Object

Source§

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

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

impl<'de> Deserialize<'de> for Object

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 Hash for Object

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 Object

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 Serialize for Object

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 Eq for Object

Auto Trait Implementations§

§

impl Freeze for Object

§

impl RefUnwindSafe for Object

§

impl Send for Object

§

impl Sync for Object

§

impl Unpin for Object

§

impl UnwindSafe for Object

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> 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>,