Trait Identifier

Source
pub trait Identifier:
    Sized
    + Clone
    + PartialEq
    + Eq
    + Hash
    + Display
    + Serialize
    + for<'de> Deserialize<'de> {
    // Required methods
    fn parse<S: AsRef<str>>(s: S) -> Result<Self, IdentifierError>;
    fn generate() -> Self;
    fn as_str(&self) -> &str;
    fn timestamp_ms(&self) -> Option<u64>;
}
Expand description

Trait for identifier types

This trait defines the common interface for different identifier types (UUID, ULID). It allows the EntityId type to be generic over the identifier implementation.

Required Methods§

Source

fn parse<S: AsRef<str>>(s: S) -> Result<Self, IdentifierError>

Parse a string into an identifier

Source

fn generate() -> Self

Generate a new random identifier

Source

fn as_str(&self) -> &str

Convert the identifier to a string representation

Source

fn timestamp_ms(&self) -> Option<u64>

Get the timestamp in milliseconds (if applicable)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§