pub struct SHA1Name { /* private fields */ }Expand description
Represents a content-addressable identifier in an Entity Resource Name (ERN).
SHA1Name uses the UUID v5 algorithm (based on SHA1 hash) to generate
deterministic, content-addressable identifiers. Unlike EntityRoot which
generates different IDs for the same input (incorporating timestamps),
SHA1Name will always generate the same ID for the same input content.
This makes SHA1Name ideal for:
- Content-addressable resources where the same content should have the same identifier
- Deterministic resource naming where reproducibility is important
- Scenarios where you want to avoid duplicate resources with the same content
Implementations§
Source§impl SHA1Name
impl SHA1Name
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 other operations.
§Example
let name1 = SHA1Name::new("document-content".to_string())?;
let name2 = SHA1Name::new("document-content".to_string())?;
// Same content produces the same ID
assert_eq!(name1.name(), name2.name());Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the string representation of this identifier.
§Example
let name = SHA1Name::new("document-content".to_string())?;
let id_str = name.as_str();
// The string will be a deterministic ID based on the content
println!("SHA1 ID: {}", id_str);Sourcepub fn new(value: String) -> Result<Self, ErnError>
pub fn new(value: String) -> Result<Self, ErnError>
Creates a new SHA1Name with the given value.
This method generates a deterministic, content-addressable identifier using
the UUID v5 algorithm based on SHA1 hash. Unlike EntityRoot, the same input
value will always produce the same ID, making it suitable for content-addressable
resources.
§Arguments
value- The string value to use for generating the SHA1 hash
§Validation Rules
- Value cannot be empty
- Value must be between 1 and 1024 characters
§Returns
Ok(SHA1Name)- If validation passesErr(ErnError)- If validation fails
§Example
let name1 = SHA1Name::new("document-content".to_string())?;
let name2 = SHA1Name::new("document-content".to_string())?;
// Same content produces the same ID
assert_eq!(name1.to_string(), name2.to_string());Trait Implementations§
Source§impl AsRef<MagicTypeId> for SHA1Name
impl AsRef<MagicTypeId> for SHA1Name
Source§fn as_ref(&self) -> &MagicTypeId
fn as_ref(&self) -> &MagicTypeId
Source§impl ErnComponent for SHA1Name
impl ErnComponent for SHA1Name
Source§impl From<MagicTypeId> for SHA1Name
impl From<MagicTypeId> for SHA1Name
Source§fn from(value: MagicTypeId) -> Self
fn from(value: MagicTypeId) -> Self
Source§impl From<SHA1Name> for MagicTypeId
impl From<SHA1Name> for MagicTypeId
Source§impl FromStr for SHA1Name
Implementation of FromStr for SHA1Name to create an entity from a string.
impl FromStr for SHA1Name
Implementation of FromStr for SHA1Name to create an entity from a string.
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a SHA1Name from a string.
This method generates a deterministic, content-addressable identifier using the UUID v5 algorithm based on SHA1 hash. The same input string will always produce the same ID.
§Arguments
s- The string value to use for generating the SHA1 hash
§Returns
Ok(SHA1Name)- If validation passesErr(ErnError)- If validation fails
§Example
let name1 = SHA1Name::from_str("document-content")?;
let name2 = SHA1Name::new("document-content".to_string())?;
// FromStr and new() produce the same result for the same input
assert_eq!(name1.to_string(), name2.to_string());