EntityRoot

Struct EntityRoot 

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

Represents the root component in an Entity Resource Name (ERN).

The root component is a unique identifier for the base resource in the ERN hierarchy. It uses the mti crate’s MagicTypeId with UUID v7 algorithm to generate time-ordered, unique identifiers that enable k-sortability.

When using EntityRoot, each call to create a new root with the same name will generate a different ID, as it incorporates the current timestamp. This makes EntityRoot suitable for resources that should be ordered by creation time.

For content-addressable, deterministic IDs, use SHA1Name instead.

Implementations§

Source§

impl EntityRoot

Source

pub fn name(&self) -> &MagicTypeId

Returns a reference to the underlying MagicTypeId.

This is useful when you need to access the raw identifier for comparison or sorting operations.

§Example
let root1 = EntityRoot::new("resource1".to_string())?;
let root2 = EntityRoot::new("resource2".to_string())?;

// Compare roots by their MagicTypeId
let comparison = root1.name().cmp(root2.name());
Source

pub fn as_str(&self) -> &str

Returns the string representation of this root’s identifier.

§Example
let root = EntityRoot::new("profile".to_string())?;
let id_str = root.as_str();

// The string will contain the original name followed by a timestamp-based suffix
assert!(id_str.starts_with("profile_"));
Source

pub fn new(value: String) -> Result<Self, ErnError>

Creates a new EntityRoot with the given value.

This method generates a time-ordered, unique identifier using the UUID v7 algorithm. Each call to this method with the same input value will generate a different ID, as it incorporates the current timestamp. This makes EntityRoot suitable for resources that should be ordered by creation time.

§Arguments
  • value - The string value to use as the base for the entity root ID
§Validation Rules
  • Value cannot be empty
  • Value must be between 1 and 255 characters
§Returns
  • Ok(EntityRoot) - If validation passes
  • Err(ErnError) - If validation fails
§Example
let root = EntityRoot::new("profile".to_string())?;

// The ID will contain the original name followed by a timestamp-based suffix
assert!(root.to_string().starts_with("profile_"));

Trait Implementations§

Source§

impl AsRef<MagicTypeId> for EntityRoot

Source§

fn as_ref(&self) -> &MagicTypeId

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for EntityRoot

Source§

fn clone(&self) -> EntityRoot

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 EntityRoot

Source§

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

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

impl Default for EntityRoot

Source§

fn default() -> EntityRoot

Returns the “default value” for a type. Read more
Source§

impl Display for EntityRoot

Source§

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

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

impl ErnComponent for EntityRoot

Source§

type NextState = Part

The type of the next component that should follow this one in the ERN structure. Read more
Source§

fn prefix() -> &'static str

Returns the prefix string that should appear before this component in an ERN. Read more
Source§

impl From<EntityRoot> for MagicTypeId

Source§

fn from(value: EntityRoot) -> Self

Converts to this type from the input type.
Source§

impl From<MagicTypeId> for EntityRoot

Source§

fn from(value: MagicTypeId) -> Self

Converts to this type from the input type.
Source§

impl FromStr for EntityRoot

Implementation of FromStr for EntityRoot to create an entity root from a string.

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Creates an EntityRoot from a string.

This method generates a time-ordered, unique identifier using the UUID v7 algorithm. Each call to this method with the same input string will generate a different ID, as it incorporates the current timestamp.

§Arguments
  • s - The string value to use as the base for the entity root ID
§Returns
  • Ok(EntityRoot) - If validation passes
  • Err(ErnError) - If validation fails
Source§

type Err = ErnError

The associated error which can be returned from parsing.
Source§

impl Hash for EntityRoot

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 EntityRoot

Source§

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

Source§

fn partial_cmp(&self, other: &EntityRoot) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for EntityRoot

Source§

impl StructuralPartialEq for EntityRoot

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
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> 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.