Struct Set

Source
pub struct Set<T>
where T: Hash,
{ /* private fields */ }

Implementations§

Source§

impl<T> Set<T>
where T: Hash + Eq,

Source

pub fn new() -> Self

Create an empty Set. Uses a HashSet internally.

Examples found in repository?
examples/simple.rs (line 5)
3fn main() {
4    // Our set doesn't need to be mutable.
5    let set = Set::new();
6    // Insert some data.
7    set.insert("hello");
8    // We now have a refefence to the data we previously inserted.
9    let hello = set.get(&"hello").unwrap();
10    // We can insert more data despite holding a reference to it.
11    set.insert("world");
12    assert_eq!(hello, set.get(&"hello").unwrap());
13}
Source

pub fn len(&self) -> usize

Returns the number of elements in the set.

Source

pub fn get(&self, value: &T) -> Option<&T>

Returns a reference to the value in the set, if any, that is equal to the given value.

Examples found in repository?
examples/simple.rs (line 9)
3fn main() {
4    // Our set doesn't need to be mutable.
5    let set = Set::new();
6    // Insert some data.
7    set.insert("hello");
8    // We now have a refefence to the data we previously inserted.
9    let hello = set.get(&"hello").unwrap();
10    // We can insert more data despite holding a reference to it.
11    set.insert("world");
12    assert_eq!(hello, set.get(&"hello").unwrap());
13}
Source

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

Adds a value to the set. If the set did not have this value present, true is returned. If the set did have this value present, false is returned.

Examples found in repository?
examples/simple.rs (line 7)
3fn main() {
4    // Our set doesn't need to be mutable.
5    let set = Set::new();
6    // Insert some data.
7    set.insert("hello");
8    // We now have a refefence to the data we previously inserted.
9    let hello = set.get(&"hello").unwrap();
10    // We can insert more data despite holding a reference to it.
11    set.insert("world");
12    assert_eq!(hello, set.get(&"hello").unwrap());
13}
Source

pub fn get_or_insert(&self, value: T) -> &T
where T: Clone,

Inserts the given value into the set if it is not present, then returns a reference to the value in the set. Currently, this implementation uses requires T: Clone, because the feature hash_set_entry isn’t stabilized yet.

Source

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

Returns true if the set contains a value.

Auto Trait Implementations§

§

impl<T> !Freeze for Set<T>

§

impl<T> !RefUnwindSafe for Set<T>

§

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

§

impl<T> !Sync for Set<T>

§

impl<T> Unpin 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> 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, 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.