Skip to main content

ContainerID

Enum ContainerID 

Source
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§

§

Root

Root container does not need an op to create. It can be created implicitly.

Fields

§container_type: ContainerType
§

Normal

Fields

§peer: PeerID
§counter: Counter
§container_type: ContainerType

Implementations§

Source§

impl ContainerID

Source

pub fn new_normal(id: ID, container_type: ContainerType) -> Self

Source

pub fn new_root(name: &str, container_type: ContainerType) -> Self

Source

pub fn name(&self) -> &InternalString

Source

pub fn container_type(&self) -> ContainerType

Source

pub fn is_unknown(&self) -> bool

Source

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.

Source

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.

Source

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

Source

pub fn is_root(&self) -> bool

Returns true if this is a ContainerID::Root, otherwise false

Source

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

Source

pub fn as_root(&self) -> Option<(&InternalString, &ContainerType)>

Optionally returns references to the inner fields if this is a ContainerID::Root, otherwise None

Source

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

Source

pub fn is_normal(&self) -> bool

Returns true if this is a ContainerID::Normal, otherwise false

Source

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

Source

pub fn as_normal(&self) -> Option<(&PeerID, &Counter, &ContainerType)>

Optionally returns references to the inner fields if this is a ContainerID::Normal, otherwise None

Source

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

Source

pub fn encode<W: Write>(&self, writer: &mut W) -> Result<(), Error>

Source

pub fn to_bytes(&self) -> Vec<u8>

Source

pub fn from_bytes(bytes: &[u8]) -> Self

Source

pub fn try_from_bytes(bytes: &[u8]) -> LoroResult<Self>

Source

pub fn to_loro_value_string(&self) -> String

Source

pub fn try_from_loro_value_string(s: &str) -> Option<Self>

Trait Implementations§

Source§

impl Clone for ContainerID

Source§

fn clone(&self) -> ContainerID

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContainerID

Source§

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

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

impl<'de> Deserialize<'de> for ContainerID

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ContainerID

Source§

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

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

impl Eq for ContainerID

Source§

impl From<ContainerID> for LoroValue

Source§

fn from(v: ContainerID) -> Self

Converts to this type from the input type.
Source§

impl Hash for ContainerID

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 ContainerID

Source§

fn eq(&self, other: &ContainerID) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Serialize for ContainerID

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ContainerID

Source§

impl TryFrom<&str> for ContainerID

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<LoroValue> for ContainerID

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from(value: LoroValue) -> Result<Self, Self::Error>

Performs the conversion.

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Rleable for T
where T: Clone + PartialEq + Serialize + for<'de> Deserialize<'de>,

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.