Skip to main content

Set

Struct Set 

Source
pub struct Set { /* private fields */ }
Expand description

A set: distinct values, sorted.

Its members lie in a balanced tree in ascending order, so looking one up, inserting or removing one costs O(log n), and a set made from a stored one shares every node the change does not touch.

Implementations§

Source§

impl Set

Source

pub fn from_items( items: impl IntoIterator<Item = Value>, ) -> Result<Set, DataError>

Returns the set of items’ distinct elements (set.from).

§Errors

A DataError when two elements cannot be compared.

Source

pub fn len(&self) -> usize

Returns how many elements there are.

Source

pub fn is_empty(&self) -> bool

Returns whether there are none.

Source

pub fn iter(&self) -> impl ExactSizeIterator<Item = &Value>

Returns the elements, in order.

Source

pub fn root(&self) -> Option<&Node<Member>>

Returns the tree the members lie in, in ascending order, or None when there are none.

Source

pub fn from_tree(root: Option<Node<Member>>) -> Set

Returns the set whose members are those of root, sharing it.

The members must ascend across the whole tree and be distinct, as those of Set::root do; the caller checks that, as reading history does, and a debug build checks it again.

Source

pub fn contains(&self, item: &Value) -> Result<bool, DataError>

Returns whether item is an element.

§Errors

A DataError when item cannot be compared with the elements.

Source

pub fn insert(self, item: Value) -> Result<Set, DataError>

Returns self with item among its elements; self itself when it already is one.

§Errors

A DataError when item cannot be compared with the elements.

Source

pub fn remove(self, item: &Value) -> Result<Set, DataError>

Returns self without item.

§Errors

A DataError when item cannot be compared with the elements.

Trait Implementations§

Source§

impl Clone for Set

Source§

fn clone(&self) -> Self

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 Set

Source§

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

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

impl Default for Set

Source§

fn default() -> Self

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

impl Drop for Set

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Set

§

impl !UnwindSafe for Set

§

impl Forget for Set

§

impl Freeze for Set
where *const ArcInner<Inner<Member>> is !null: Freeze, PhantomData<ArcInner<Inner<Member>>>: Freeze,

§

impl Move for Set

§

impl Send for Set
where Arc<Inner<Member>>: Send,

§

impl Sync for Set
where Arc<Inner<Member>>: Sync,

§

impl Unpin for Set
where Arc<Inner<Member>>: Unpin,

§

impl UnsafeUnpin for Set
where *const ArcInner<Inner<Member>> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner<Member>>>: UnsafeUnpin,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.