pub enum ContainerID {
Root {
name: InternalString,
container_type: ContainerType,
},
Normal {
peer: PeerID,
counter: Counter,
container_type: ContainerType,
},
}Expand description
ContainerID includes the Op’s ID and the type. So it’s impossible to have the same ContainerID with conflict ContainerType.
This structure is really cheap to clone.
String representation:
- Root Container:
/<name>:<type> - Normal Container:
<counter>@<client>:<type>
Note: It will be encoded into binary format, so the order of its fields should not be changed.
Variants§
Implementations§
Source§impl ContainerID
impl ContainerID
pub fn new_normal(id: ID, container_type: ContainerType) -> Self
pub fn new_root(name: &str, container_type: ContainerType) -> Self
pub fn name(&self) -> &InternalString
pub fn container_type(&self) -> ContainerType
pub fn is_unknown(&self) -> bool
Sourcepub fn new_mergeable(
parent: &ContainerID,
key: &str,
container_type: ContainerType,
) -> Self
pub fn new_mergeable( parent: &ContainerID, key: &str, container_type: ContainerType, ) -> Self
Create a mergeable container ID for the given parent, key, and container type.
The cid is a Root container with a reserved namespace prefix and a flattened
map-path payload, so two peers calling this with the same arguments produce the
identical ContainerID.
The container kind is intentionally not encoded into the name: it already
lives in ContainerID::Root::container_type, so encoding it twice would waste two
bytes per cid, and ContainerID equality already keeps two (parent, key)
mergeable cids of different kinds distinct.
Only maps can be mergeable parents. The encoded payload records the nearest
non-mergeable map ancestor ($root-name or @peer:counter) once, then appends
escaped map keys separated by >. This keeps nested mergeable map names linear
in path length instead of recursively embedding the full parent cid.
Sourcepub fn is_mergeable(&self) -> bool
pub fn is_mergeable(&self) -> bool
Returns true if this is a valid mergeable container ID (i.e. created via
new_mergeable).
A Root whose name merely starts with the reserved mergeable prefix but does not
decode to a valid path payload is an ordinary root, not a mergeable
container. The check is structural; a fabricated "🤝:not-valid" Root is not
treated as mergeable.
Constant-time short-circuit when the name doesn’t start with the mergeable prefix (most container ids). For names that do match the prefix, validates segment escaping and the compact base-parent encoding.
Sourcepub fn parse_mergeable(&self) -> Option<(ContainerID, String, ContainerType)>
pub fn parse_mergeable(&self) -> Option<(ContainerID, String, ContainerType)>
Decode a mergeable container ID back into its (parent, key, container_type) components.
Returns None if this is not a valid mergeable container ID. The returned
container_type is the type carried on the Root itself; the encoded payload only
carries (parent, key).
Source§impl ContainerID
impl ContainerID
Sourcepub fn as_root_mut(
&mut self,
) -> Option<(&mut InternalString, &mut ContainerType)>
pub fn as_root_mut( &mut self, ) -> Option<(&mut InternalString, &mut ContainerType)>
Optionally returns mutable references to the inner fields if this is a ContainerID::Root, otherwise None
Sourcepub fn as_root(&self) -> Option<(&InternalString, &ContainerType)>
pub fn as_root(&self) -> Option<(&InternalString, &ContainerType)>
Optionally returns references to the inner fields if this is a ContainerID::Root, otherwise None
Sourcepub fn into_root(self) -> Result<(InternalString, ContainerType), Self>
pub fn into_root(self) -> Result<(InternalString, ContainerType), Self>
Returns the inner fields if this is a ContainerID::Root, otherwise returns back the enum in the Err case of the result
Sourcepub fn as_normal_mut(
&mut self,
) -> Option<(&mut PeerID, &mut Counter, &mut ContainerType)>
pub fn as_normal_mut( &mut self, ) -> Option<(&mut PeerID, &mut Counter, &mut ContainerType)>
Optionally returns mutable references to the inner fields if this is a ContainerID::Normal, otherwise None
Sourcepub fn as_normal(&self) -> Option<(&PeerID, &Counter, &ContainerType)>
pub fn as_normal(&self) -> Option<(&PeerID, &Counter, &ContainerType)>
Optionally returns references to the inner fields if this is a ContainerID::Normal, otherwise None
Sourcepub fn into_normal(self) -> Result<(PeerID, Counter, ContainerType), Self>
pub fn into_normal(self) -> Result<(PeerID, Counter, ContainerType), Self>
Returns the inner fields if this is a ContainerID::Normal, otherwise returns back the enum in the Err case of the result
Source§impl ContainerID
impl ContainerID
pub fn encode<W: Write>(&self, writer: &mut W) -> Result<(), Error>
pub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn from_bytes(bytes: &[u8]) -> Self
pub fn try_from_bytes(bytes: &[u8]) -> LoroResult<Self>
pub fn to_loro_value_string(&self) -> String
pub fn try_from_loro_value_string(s: &str) -> Option<Self>
Trait Implementations§
Source§impl Clone for ContainerID
impl Clone for ContainerID
Source§fn clone(&self) -> ContainerID
fn clone(&self) -> ContainerID
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContainerID
impl Debug for ContainerID
Source§impl<'de> Deserialize<'de> for ContainerID
impl<'de> Deserialize<'de> for ContainerID
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>,
Source§impl Display for ContainerID
impl Display for ContainerID
impl Eq for ContainerID
Source§impl From<ContainerID> for LoroValue
impl From<ContainerID> for LoroValue
Source§fn from(v: ContainerID) -> Self
fn from(v: ContainerID) -> Self
Source§impl Hash for ContainerID
impl Hash for ContainerID
Source§impl PartialEq for ContainerID
impl PartialEq for ContainerID
Source§fn eq(&self, other: &ContainerID) -> bool
fn eq(&self, other: &ContainerID) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for ContainerID
impl Serialize for ContainerID
impl StructuralPartialEq for ContainerID
Source§impl TryFrom<&str> for ContainerID
impl TryFrom<&str> for ContainerID
Auto Trait Implementations§
impl Freeze for ContainerID
impl RefUnwindSafe for ContainerID
impl Send for ContainerID
impl Sync for ContainerID
impl Unpin for ContainerID
impl UnsafeUnpin for ContainerID
impl UnwindSafe for ContainerID
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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>
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>
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 more