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>
impl<K: Ord + Eq> TlsSet<K>
Sourcepub fn from_keys(iter: impl IntoIterator<Item = K>) -> Self
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);Sourcepub fn insert(&mut self, key: K) -> Result<(), TlsSetError>
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()); // duplicateSourcepub fn remove(&mut self, key: &K) -> Result<(), TlsSetError>
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 removedSource§impl<K: Ord + Eq + Clone + Serialize + Size> TlsSet<K>
impl<K: Ord + Eq + Clone + Serialize + Size> TlsSet<K>
Sourcepub fn apply_delta(&mut self, delta: TlsSetDelta<K>) -> Result<(), TlsSetError>
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, wherenis the current set size andmis 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. WhenRemoveByHashis present, an additional O(n)HashMapis 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> Deserialize for TlsSet<K>
impl<K> Deserialize for TlsSet<K>
Source§fn tls_deserialize<R: Read>(bytes: &mut R) -> Result<Self, Error>where
Self: Sized,
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 moreSource§impl<K: Ord + Eq> FromIterator<K> for TlsSet<K>
impl<K: Ord + Eq> FromIterator<K> for TlsSet<K>
Source§fn from_iter<T: IntoIterator<Item = K>>(iter: T) -> Self
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>
impl<K> IntoIterator for TlsSet<K>
impl<K: Eq> Eq for TlsSet<K>
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
impl<T> AggregateExpressionMethods for T
§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read more§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read more§fn aggregate_filter<P>(self, f: P) -> Self::Outputwhere
P: AsExpression<Bool>,
Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,
fn aggregate_filter<P>(self, f: P) -> Self::Outputwhere
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::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Add an aggregate function order Read more
§impl<'a, F, I> BatchInvert<F> for I
impl<'a, F, I> BatchInvert<F> for I
§fn batch_invert(self) -> 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> 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn 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>
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)
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)
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
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<T> IntoSql for T
impl<T> IntoSql for T
§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
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
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<S, T> Upcast<T> for S
impl<S, T> Upcast<T> for S
§impl<T> WindowExpressionMethods for T
impl<T> WindowExpressionMethods for T
§fn over(self) -> Self::Outputwhere
Self: OverDsl,
fn over(self) -> Self::Outputwhere
Self: OverDsl,
Turn a function call into a window function call Read more
§fn window_filter<P>(self, f: P) -> Self::Outputwhere
P: AsExpression<Bool>,
Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,
fn window_filter<P>(self, f: P) -> Self::Outputwhere
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::Outputwhere
Self: PartitionByDsl<E>,
fn partition_by<E>(self, expr: E) -> Self::Outputwhere
Self: PartitionByDsl<E>,
Add a partition clause to the current window function Read more
§fn window_order<E>(self, expr: E) -> Self::Outputwhere
Self: OrderWindowDsl<E>,
fn window_order<E>(self, expr: E) -> Self::Outputwhere
Self: OrderWindowDsl<E>,
Add a order clause to the current window function Read more