pub struct PersistenceId(/* private fields */);Expand description
Stable identity of one persistent entity.
PersistenceId::new creates the conventional entity_type|entity_id
form. PersistenceId::from_unique accepts an already-composed unique id;
if it contains |, accessors split at the first occurrence, matching Akka’s
extraction semantics.
Backed by Arc<str> rather than String. Every event a running entity
persists carries its own copy of the persistence id (see
StoredEvent::persistence_id in crate::journal), and the behavior/state
runtimes clone it once per stored event. Arc<str> makes Clone an
atomic refcount bump instead of a heap allocation plus byte copy of the
full entity_type|entity_id string. PartialEq/Eq/PartialOrd/Ord/
Hash/Display/Debug all delegate through Arc’s deref to the
contained str, so comparisons, ordering, hashing, and formatted output
are unchanged from the previous String storage — this is purely an
internal representation change; the public constructor/accessor API is
identical.
Implementations§
Source§impl PersistenceId
impl PersistenceId
Sourcepub fn new(
entity_type: impl Into<String>,
entity_id: impl Into<String>,
) -> PersistenceResult<Self>
pub fn new( entity_type: impl Into<String>, entity_id: impl Into<String>, ) -> PersistenceResult<Self>
Creates an id from an entity type and entity id using | as separator.
Neither component may contain the separator.
Sourcepub fn from_unique(id: impl Into<String>) -> PersistenceResult<Self>
pub fn from_unique(id: impl Into<String>) -> PersistenceResult<Self>
Creates an id from its complete, already-unique representation.
This is the Rust-native spelling of Akka’s ofUniqueId. A unique id
need not use the conventional separator, but it must not be blank.
Sourcepub fn entity_type(&self) -> &str
pub fn entity_type(&self) -> &str
Returns the entity type, or an empty string when the id has no separator.