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
impl EntityRoot
Sourcepub fn name(&self) -> &MagicTypeId
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());Sourcepub fn as_str(&self) -> &str
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_"));Sourcepub fn new(value: String) -> Result<Self, ErnError>
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 passesErr(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
impl AsRef<MagicTypeId> for EntityRoot
Source§fn as_ref(&self) -> &MagicTypeId
fn as_ref(&self) -> &MagicTypeId
Source§impl Clone for EntityRoot
impl Clone for EntityRoot
Source§fn clone(&self) -> EntityRoot
fn clone(&self) -> EntityRoot
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EntityRoot
impl Debug for EntityRoot
Source§impl Default for EntityRoot
impl Default for EntityRoot
Source§fn default() -> EntityRoot
fn default() -> EntityRoot
Source§impl Display for EntityRoot
impl Display for EntityRoot
Source§impl ErnComponent for EntityRoot
impl ErnComponent for EntityRoot
Source§impl From<EntityRoot> for MagicTypeId
impl From<EntityRoot> for MagicTypeId
Source§fn from(value: EntityRoot) -> Self
fn from(value: EntityRoot) -> Self
Source§impl From<MagicTypeId> for EntityRoot
impl From<MagicTypeId> for EntityRoot
Source§fn from(value: MagicTypeId) -> Self
fn from(value: MagicTypeId) -> Self
Source§impl FromStr for EntityRoot
Implementation of FromStr for EntityRoot to create an entity root from a string.
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>
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 passesErr(ErnError)- If validation fails