pub struct EntityId(/* private fields */);Expand description
Value Object: EntityId
Represents a unique identifier for an entity in the event sourcing system. Entities are the subjects of events (e.g., user-123, order-456, product-789).
Domain Rules:
- Cannot be empty
- Must be between 1 and 128 characters
- Flexible format (allows any printable characters except whitespace)
- Case-sensitive
- Immutable once created
This is a Value Object:
- Defined by its value, not identity
- Immutable
- Self-validating
- Compared by value equality
Implementations§
Source§impl EntityId
impl EntityId
Sourcepub fn new(value: String) -> Result<Self>
pub fn new(value: String) -> Result<Self>
Create a new EntityId with validation
§Errors
Returns error if:
- ID is empty
- ID is longer than 128 characters
- ID contains only whitespace
- ID contains control characters
§Examples
use allsource_core::domain::value_objects::EntityId;
let entity_id = EntityId::new("user-123".to_string()).unwrap();
assert_eq!(entity_id.as_str(), "user-123");
let entity_id = EntityId::new("order_ABC-456".to_string()).unwrap();
assert_eq!(entity_id.as_str(), "order_ABC-456");Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Get the inner String (consumes self)
Sourcepub fn starts_with(&self, prefix: &str) -> bool
pub fn starts_with(&self, prefix: &str) -> bool
Check if this entity ID starts with a specific prefix
§Examples
use allsource_core::domain::value_objects::EntityId;
let entity_id = EntityId::new("user-123".to_string()).unwrap();
assert!(entity_id.starts_with("user-"));
assert!(!entity_id.starts_with("order-"));Sourcepub fn ends_with(&self, suffix: &str) -> bool
pub fn ends_with(&self, suffix: &str) -> bool
Check if this entity ID ends with a specific suffix
§Examples
use allsource_core::domain::value_objects::EntityId;
let entity_id = EntityId::new("user-123".to_string()).unwrap();
assert!(entity_id.ends_with("-123"));
assert!(!entity_id.ends_with("-456"));Sourcepub fn prefix(&self, delimiter: char) -> Option<&str>
pub fn prefix(&self, delimiter: char) -> Option<&str>
Extract a prefix before a delimiter (if present)
§Examples
use allsource_core::domain::value_objects::EntityId;
let entity_id = EntityId::new("user-123".to_string()).unwrap();
assert_eq!(entity_id.prefix('-'), Some("user"));
let entity_id = EntityId::new("simple".to_string()).unwrap();
assert_eq!(entity_id.prefix('-'), None);Trait Implementations§
Source§impl<'de> Deserialize<'de> for EntityId
impl<'de> Deserialize<'de> for EntityId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for EntityId
impl StructuralPartialEq for EntityId
Auto Trait Implementations§
impl Freeze for EntityId
impl RefUnwindSafe for EntityId
impl Send for EntityId
impl Sync for EntityId
impl Unpin for EntityId
impl UnwindSafe for EntityId
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.