Skip to main content

Set

Struct Set 

Source
pub struct Set<T: Eq + Hash + Clone> { /* private fields */ }
Expand description

OR-Set CRDT. See the module docs for semantics.

Implementations§

Source§

impl<T: Eq + Hash + Clone> Set<T>

Source

pub fn new(replica: ReplicaId) -> Self

Create an empty set.

Source

pub fn new_random() -> Self

Create a new instance with a random ReplicaId from OS entropy. See crate::new_replica_id.

Source

pub fn replica_id(&self) -> ReplicaId

This replica’s id.

Source

pub fn len(&self) -> usize

Number of distinct values currently in the set.

Source

pub fn is_empty(&self) -> bool

Is the set empty?

Source

pub fn contains(&self, value: &T) -> bool

Does the set contain value?

Source

pub fn iter(&self) -> impl Iterator<Item = &T> + '_

Iterate over values currently in the set.

Source

pub fn add(&mut self, value: T) -> SetOp<T>

Add value. If it’s already present, an additional tag is created; removing it then requires a remove op that observes both tags (which always happens when removes carry the tag list at remove-time).

Source

pub fn remove(&mut self, value: &T) -> Option<SetOp<T>>

Remove value. No-op (returns None) if the value is not present.

Source

pub fn apply(&mut self, op: SetOp<T>) -> Result<(), Error>

Apply a remote op. Idempotent.

Source

pub fn merge(&mut self, other: &Self)

Merge all of other’s state into self.

Source

pub fn ops(&self) -> &[SetOp<T>]

All ops in this set’s log.

Source

pub fn ops_since<'a>( &'a self, since: &'a VersionVector, ) -> impl Iterator<Item = &'a SetOp<T>> + 'a

Iterate over ops not yet seen by since.

Source

pub fn version(&self) -> &VersionVector

This replica’s current version vector.

Trait Implementations§

Source§

impl<T: Clone + Eq + Hash + Clone> Clone for Set<T>

Source§

fn clone(&self) -> Set<T>

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<T: Debug + Eq + Hash + Clone> Debug for Set<T>

Source§

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

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

impl<T: Eq + Hash + Clone> Default for Set<T>

Source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for Set<T>
where T: Eq + Hash + Clone + Deserialize<'de>,

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>

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

impl<T> Serialize for Set<T>
where T: Eq + Hash + Clone + Serialize,

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Set<T>

§

impl<T> RefUnwindSafe for Set<T>
where T: RefUnwindSafe,

§

impl<T> Send for Set<T>
where T: Send,

§

impl<T> Sync for Set<T>
where T: Sync,

§

impl<T> Unpin for Set<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Set<T>

§

impl<T> UnwindSafe for Set<T>
where T: UnwindSafe,

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