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 from a bare 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.
A value that is already a fully-formed identifier (for example one taken from an
existing ERN) is preserved as-is rather than reissued, so ERNs round-trip through
parsing and serialization unchanged.
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 name_str(&self) -> &str
pub fn name_str(&self) -> &str
Returns the human-readable name of this root, without the generated suffix.
Where as_str yields the full identifier (worker_01h455vb4pex…),
this yields just the name it was created from (worker). That name is stable across
roots minted from the same input, which makes it the right value to derive a
deterministic child path from:
let parent = Ern::with_root("pool")?;
let requested = Ern::with_root("worker")?;
// Same child every time, regardless of when `requested` was minted
let child = parent.add_part(requested.name())?;
assert_eq!(child, parent.add_part(requested.name())?);Returns an empty string for a root that carries no prefix, such as one built from a
bare suffix or EntityRoot::default.
§Example
let root = EntityRoot::new("profile".to_string())?;
assert_eq!(root.name_str(), "profile");
assert!(root.as_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.
When value is a bare name, this method generates a time-ordered, unique identifier
using the UUID v7 algorithm. Each call 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.
When value is already a fully-formed identifier, it is preserved verbatim so that
existing roots survive a parse or deserialization round trip.
§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_"));
// Re-creating from a formed identifier preserves it
let same = EntityRoot::new(root.to_string())?;
assert_eq!(root, same);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 (const: unstable) · 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
impl Eq for EntityRoot
Source§impl ErnComponent for EntityRoot
impl ErnComponent for EntityRoot
Source§type NextState = Part
type NextState = Part
Source§fn prefix() -> &'static str
fn prefix() -> &'static str
Source§fn build_root(value: &str) -> Option<Result<EntityRoot, ErnError>>
fn build_root(value: &str) -> Option<Result<EntityRoot, ErnError>>
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.
A bare name receives a freshly minted, time-ordered v7 identifier, so each call with
the same name yields a different ID. A string that is already a fully-formed
identifier is preserved verbatim, which is what allows ErnParser to round-trip an
ERN’s own Display output.
§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