Skip to main content

TlsSet

Struct TlsSet 

Source
pub struct TlsSet<K> { /* private fields */ }
Expand description

A sorted set with deterministic TLS codec serialization.

§Examples

use xmtp_mls_common::tls_set::TlsSet;
use tls_codec::{Serialize, Deserialize};

let mut set = TlsSet::<u16>::new();
set.insert(3).unwrap();
set.insert(1).unwrap();
set.insert(2).unwrap();

let bytes = set.tls_serialize_detached().unwrap();
let deserialized = TlsSet::<u16>::tls_deserialize_exact(&bytes).unwrap();
assert_eq!(set, deserialized);

Implementations§

Source§

impl<K: Ord + Eq> TlsSet<K>

Source

pub fn new() -> Self

Create an empty set.

Source

pub fn from_keys(iter: impl IntoIterator<Item = K>) -> Self

Create a set from an iterator of keys. Duplicates are silently ignored.

use xmtp_mls_common::tls_set::TlsSet;

let set = TlsSet::from_keys([3, 1, 2, 1]);
assert_eq!(set.len(), 3);
Source

pub fn insert(&mut self, key: K) -> Result<(), TlsSetError>

Insert a key. Returns an error if the key already exists.

use xmtp_mls_common::tls_set::TlsSet;

let mut set = TlsSet::<u8>::new();
assert!(set.insert(1).is_ok());
assert!(set.insert(1).is_err()); // duplicate
Source

pub fn remove(&mut self, key: &K) -> Result<(), TlsSetError>

Remove a key. Returns an error if the key doesn’t exist.

use xmtp_mls_common::tls_set::TlsSet;

let mut set = TlsSet::<u8>::new();
set.insert(1).unwrap();
assert!(set.remove(&1).is_ok());
assert!(set.remove(&1).is_err()); // already removed
Source

pub fn contains(&self, key: &K) -> bool

Returns true if the set contains the key.

Source

pub fn len(&self) -> usize

Returns the number of elements in the set.

Source

pub fn is_empty(&self) -> bool

Returns true if the set is empty.

Source

pub fn iter(&self) -> impl Iterator<Item = &K>

Iterate over keys in sorted order.

use xmtp_mls_common::tls_set::TlsSet;

let set = TlsSet::from_keys([3, 1, 2]);
let keys: Vec<_> = set.iter().collect();
assert_eq!(keys, vec![&1, &2, &3]);
Source§

impl<K: Ord + Eq + Clone + Serialize + Size> TlsSet<K>

Source

pub fn apply_delta(&mut self, delta: TlsSetDelta<K>) -> Result<(), TlsSetError>

Apply a delta atomically. If any mutation fails, the set is unchanged.

If the delta contains any RemoveByHash mutations, a hash index of all existing keys is built once (O(n)) and used for lookups (O(1) each), avoiding O(n*m) behavior. Returns TlsSetError::DuplicateHash if two existing keys produce the same SHA-256 hash.

§Performance
  • Time: O(n + m) when the delta contains any RemoveByHash (one O(n) index build, then O(1) per lookup), or O(m) otherwise, where n is the current set size and m is the mutation count.
  • Memory: O(m) — all mutations are resolved into a temporary Vec<TlsMapMutation> before being applied. This allocation is required to preserve atomicity: resolution must complete before any actual mutation happens, so a partial delta cannot leave the set in an inconsistent state. When RemoveByHash is present, an additional O(n) HashMap is allocated for the hash index, holding borrowed key references (no key cloning during index build).
use xmtp_mls_common::tls_set::{TlsSet, TlsSetDelta};

let mut set = TlsSet::<u8>::new();
set.insert(1).unwrap();

let delta = TlsSetDelta::new().insert(2).remove(1);
set.apply_delta(delta).unwrap();
assert!(set.contains(&2));
assert!(!set.contains(&1));

Trait Implementations§

Source§

impl<K: Clone> Clone for TlsSet<K>

Source§

fn clone(&self) -> TlsSet<K>

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<K: Debug> Debug for TlsSet<K>

Source§

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

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

impl<K> Default for TlsSet<K>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K> Deserialize for TlsSet<K>
where K: Deserialize + Size + Ord + Eq,

Source§

fn tls_deserialize<R: Read>(bytes: &mut R) -> Result<Self, Error>
where Self: Sized,

This function deserializes the bytes from the provided a std::io::Read and returns the populated struct. Read more
§

fn tls_deserialize_exact(bytes: impl AsRef<[u8]>) -> Result<Self, Error>
where Self: Sized,

This function deserializes the provided bytes and returns the populated struct. All bytes must be consumed. Read more
Source§

impl<K: Ord + Eq> FromIterator<K> for TlsSet<K>

Source§

fn from_iter<T: IntoIterator<Item = K>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<K> IntoIterator for TlsSet<K>

Source§

type Item = K

The type of the elements being iterated over.
Source§

type IntoIter = Map<<TlsMap<K, ()> as IntoIterator>::IntoIter, fn((K, ())) -> K>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K: PartialEq> PartialEq for TlsSet<K>

Source§

fn eq(&self, other: &TlsSet<K>) -> 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<K: Serialize + Size + Debug> Serialize for TlsSet<K>

Source§

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

Serialize self and write it to the writer. The function returns the number of bytes written to writer.
§

fn tls_serialize_detached(&self) -> Result<Vec<u8>, Error>

Serialize self and return it as a byte vector.
Source§

impl<K: Size> Size for TlsSet<K>

Source§

impl<K: Eq> Eq for TlsSet<K>

Source§

impl<K> StructuralPartialEq for TlsSet<K>

Auto Trait Implementations§

§

impl<K> Freeze for TlsSet<K>

§

impl<K> RefUnwindSafe for TlsSet<K>
where K: RefUnwindSafe,

§

impl<K> Send for TlsSet<K>
where K: Send,

§

impl<K> Sync for TlsSet<K>
where K: Sync,

§

impl<K> Unpin for TlsSet<K>
where K: Unpin,

§

impl<K> UnsafeUnpin for TlsSet<K>

§

impl<K> UnwindSafe for TlsSet<K>
where K: UnwindSafe,

Blanket Implementations§

§

impl<T> AggregateExpressionMethods for T

§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, F, I> BatchInvert<F> for I
where F: Field + ConstantTimeEq, I: IntoIterator<Item = &'a mut F>,

§

fn batch_invert(self) -> F

Consumes this iterator and inverts each field element (when nonzero). Zero-valued elements are left as zero. 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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

impl<T> Identity for T
where T: ?Sized,

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> IntoSql for T

§

fn into_sql<T>(self) -> Self::Expression
where Self: Sized + AsExpression<T>, T: SqlType + TypedExpressionType,

Convert self to an expression for Diesel’s query builder. Read more
§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, 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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WindowExpressionMethods for T

§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,