Struct VecSet

Source
pub struct VecSet<T>(/* private fields */);
Expand description

An set of items stored in order in a Vec.

This is always efficient for small sizes of sets, and efficient for large sizes when insertion is not needed (i.e. items are placed into the set in bulk).

Implementations§

Source§

impl<T: Eq + PartialEq + Ord + PartialOrd> VecSet<T>

Source

pub fn new() -> Self

Create a new, empty instance.

Source

pub fn from_sorted(v: Vec<T>) -> Result<Self, ()>

Create a new instance from a sorted Vec.

Returns Ok with an instance containing the same items as v, or Err if v is unsorted.

Source

pub fn len(&self) -> usize

Return the number of items this set contains.

Source

pub fn is_empty(&self) -> bool

Return true if this set is empty.

Source

pub fn is_disjoint(&self, other: &Self) -> bool

Compares the items in two sets.

Returns true iff every item in the set is not found in other.

Source

pub fn iter(&self) -> Iter<'_, T>

Return an iterator over the items in this set in order.

Source

pub fn map<U>(self, f: impl FnMut(T) -> U) -> Vec<U>

Consume this set and return a Vec of transformed items.

Returns the Vec of the resultant values of applying f to each item in the set in order.

Source

pub fn map_ref<U>(&self, f: impl FnMut(&T) -> U) -> Vec<U>

Transform all items by reference and return a Vec with the results.

Returns the Vec of the resultant values of applying f to each item by reference in the set in order.

Source

pub fn to_vec(&self) -> Vec<T>
where T: Clone,

Return a Vec of sorted items by cloning this set.

Source

pub fn into_vec(self) -> Vec<T>

Return a Vec of sorted items by consuming this set.

Source

pub fn insert(&mut self, t: T) -> bool

Insert item into the set.

Inserts some item t into the set.

Returns true iff the item was not already in the set.

Source

pub fn extend(&mut self, iter: impl IntoIterator<Item = T>)

Insert multiple items from an iterator.

Source

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

Check if a value is in the set.

Returns true iff the set contains a value equal to t.

Source

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

Remove an item from the set.

Removes the item equal to t from the set.

Returns Some with the removed item if it was previously in the set.

Source

pub fn retain(&mut self, f: impl FnMut(&T) -> bool)

Filter items from the set.

Removes all items from the set for which f returns false.

Trait Implementations§

Source§

impl<T> AsMut<[T]> for VecSet<T>

Source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T> AsRef<[T]> for VecSet<T>

Source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone> Clone for VecSet<T>

Source§

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

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for VecSet<T>

Source§

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

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

impl<T: Decode + Eq + PartialEq + Ord + PartialOrd> Decode for VecSet<T>

Source§

fn decode<I: Input>(input: &mut I) -> Result<Self, DecodeError>

Attempt to deserialise the value from input.
Source§

fn decode_into<I>( input: &mut I, dst: &mut MaybeUninit<Self>, ) -> Result<DecodeFinished, Error>
where I: Input,

Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
Source§

fn skip<I>(input: &mut I) -> Result<(), Error>
where I: Input,

Attempt to skip the encoded value from input. Read more
Source§

fn encoded_fixed_size() -> Option<usize>

Returns the fixed encoded size of the type. Read more
Source§

impl<T: Default + Eq + PartialEq + Ord + PartialOrd> Default for VecSet<T>

Source§

fn default() -> Self

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

impl<T: Display> Display for VecSet<T>

Source§

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

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

impl<T> Encode for VecSet<T>
where Vec<T>: Encode,

Source§

fn size_hint(&self) -> usize

If possible give a hint of expected size of the encoding. Read more
Source§

fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )

Convert self to a slice and append it to the destination.
Source§

fn encode(&self) -> Vec<u8>

Convert self to an owned vector.
Source§

fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>( &self, f: __CodecUsingEncodedCallback, ) -> __CodecOutputReturn

Convert self to a slice and then invoke the given closure with it.
Source§

fn encoded_size(&self) -> usize

Calculates the encoded size. Read more
Source§

impl<T: Eq + PartialEq + Ord + PartialOrd> Extend<T> for VecSet<T>

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T: Eq + PartialEq + Ord + PartialOrd> From<Vec<T>> for VecSet<T>

Source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<VecSet<T>> for Vec<T>

Source§

fn from(s: VecSet<T>) -> Vec<T>

Converts to this type from the input type.
Source§

impl<T: Eq + PartialEq + Ord + PartialOrd> FromIterator<T> for VecSet<T>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T: Eq + PartialEq + Ord + PartialOrd> IntoIterator for VecSet<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = <Vec<T> as IntoIterator>::IntoIter

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<T: Ord> Ord for VecSet<T>

Source§

fn cmp(&self, other: &VecSet<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for VecSet<T>

Source§

fn eq(&self, other: &VecSet<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<T: PartialOrd> PartialOrd for VecSet<T>

Source§

fn partial_cmp(&self, other: &VecSet<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Eq + PartialEq + Ord + PartialOrd> SetLike<T> for VecSet<T>

Source§

fn insert(&mut self, t: T) -> bool

Insert item into the set. Read more
Source§

fn extend(&mut self, iter: impl Iterator<Item = T>)

Insert multiple items from an iterator.
Source§

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

Check if a value is in the set. Read more
Source§

fn remove(&mut self, t: &T) -> bool

Remove an item from the set. Read more
Source§

impl<T> EncodeLike for VecSet<T>
where Vec<T>: Encode,

Source§

impl<T: Eq> Eq for VecSet<T>

Source§

impl<T> StructuralPartialEq for VecSet<T>

Auto Trait Implementations§

§

impl<T> Freeze for VecSet<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for VecSet<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, U> AsByteSlice<T> for U
where T: ToByteSlice, U: AsRef<[T]> + ?Sized,

Source§

fn as_byte_slice(&self) -> &[u8]

Source§

impl<T, U> AsMutByteSlice<T> for U
where T: ToMutByteSlice, U: AsMut<[T]> + ?Sized,

Source§

fn as_mut_byte_slice(&mut self) -> &mut [u8]

Source§

impl<U> AsMutSliceOf for U
where U: AsMut<[u8]> + ?Sized,

Source§

fn as_mut_slice_of<T>(&mut self) -> Result<&mut [T], Error>
where T: FromByteSlice,

Source§

impl<U> AsSliceOf for U
where U: AsRef<[u8]> + ?Sized,

Source§

fn as_slice_of<T>(&self) -> Result<&[T], Error>
where T: FromByteSlice,

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> DecodeAll for T
where T: Decode,

Source§

fn decode_all(input: &mut &[u8]) -> Result<T, Error>

Decode Self and consume all of the given input data. Read more
Source§

impl<T> DecodeLimit for T
where T: Decode,

Source§

fn decode_all_with_depth_limit( limit: u32, input: &mut &[u8], ) -> Result<T, Error>

Decode Self and consume all of the given input data. Read more
Source§

fn decode_with_depth_limit<I>(limit: u32, input: &mut I) -> Result<T, Error>
where I: Input,

Decode Self with the given maximum recursion depth and advance input by the number of bytes consumed. 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> KeyedVec for T
where T: Codec,

Source§

fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8>

Return an encoding of Self prepended by given slice.
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.
Source§

impl<S> Codec for S
where S: Decode + Encode,

Source§

impl<T> EncodeLike<&&T> for T
where T: Encode,

Source§

impl<T> EncodeLike<&T> for T
where T: Encode,

Source§

impl<T> EncodeLike<&mut T> for T
where T: Encode,

Source§

impl<T> EncodeLike<Arc<T>> for T
where T: Encode,

Source§

impl<T> EncodeLike<Box<T>> for T
where T: Encode,

Source§

impl<T> EncodeLike<Cow<'_, T>> for T
where T: ToOwned + Encode,

Source§

impl<T> EncodeLike<Rc<T>> for T
where T: Encode,

Source§

impl<S> FullCodec for S
where S: Decode + FullEncode,

Source§

impl<S> FullEncode for S
where S: Encode + EncodeLike,

Source§

impl<T> JsonSchemaMaybe for T