SHA1Name

Struct SHA1Name 

Source
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

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 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());
Source

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);
Source

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 passes
  • Err(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

Source§

fn as_ref(&self) -> &MagicTypeId

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

impl Clone for SHA1Name

Source§

fn clone(&self) -> SHA1Name

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 SHA1Name

Source§

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

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

impl Default for SHA1Name

Source§

fn default() -> SHA1Name

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

impl Display for SHA1Name

Source§

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

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

impl ErnComponent for SHA1Name

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<MagicTypeId> for SHA1Name

Source§

fn from(value: MagicTypeId) -> Self

Converts to this type from the input type.
Source§

impl From<SHA1Name> for MagicTypeId

Source§

fn from(value: SHA1Name) -> Self

Converts to this type from the input type.
Source§

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>

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 passes
  • Err(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());
Source§

type Err = ErnError

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

impl Hash for SHA1Name

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 SHA1Name

Source§

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

Source§

fn partial_cmp(&self, other: &SHA1Name) -> 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 SHA1Name

Source§

impl StructuralPartialEq for SHA1Name

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.