Struct json_api::value::collections::set::Set [] [src]

pub struct Set<T: Eq + Hash = Key> { /* fields omitted */ }

A hash set implemented as a Map where the value is ().

Methods

impl<T: Eq + Hash> Set<T>
[src]

[src]

Creates an empty Set.

Example

use json_api::value::{Key, Set};
let mut set = Set::<Key>::new();

[src]

Creates a new empty Set, with specified capacity.

Example

let mut set = Set::with_capacity(2);

set.insert("x");
set.insert("y");

// The next insert will likely require reallocation...
set.insert("z");

[src]

Returns the number of elements the set can hold without reallocating.

Example

let set = Set::<Key>::with_capacity(2);
assert!(set.capacity() >= 2);

[src]

Clears the set, removing all elements. Keeps the allocated memory for reuse.

Example

let mut set = Set::new();

set.insert("x");
set.clear();
assert!(set.is_empty());

[src]

Returns true if the set contains the specified value.

Example

let mut set = Set::new();

set.insert(1);
assert!(set.contains(&1));
assert!(!set.contains(&2));

[src]

Clears the set, returning all elements in an iterator. Keeps the allocated memory for reuse.

Example

let mut set = Set::new();

set.insert(1);
set.insert(2);

for item in set.drain(..) {
    assert!(item == 1 || item == 2);
}

assert!(set.is_empty());

[src]

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.

Example

let mut set = Set::new();

assert_eq!(set.insert(1), true);
assert_eq!(set.insert(1), false);
assert_eq!(set.len(), 1);

[src]

Returns true if the set does not contain any elements.

Example

let mut set = Set::new();
assert!(set.is_empty());

set.insert("x");
assert!(!set.is_empty());

[src]

Return an iterator visiting all the elements of the set in the order in which they were inserted.

Example

let mut set = Set::new();

set.insert("a");
set.insert("b");
set.insert("c");

let mut iter = set.iter();

assert_eq!(iter.next(), Some(&"a"));
assert_eq!(iter.next(), Some(&"b"));
assert_eq!(iter.next(), Some(&"c"));
assert_eq!(iter.next(), None);

[src]

Return the number of elements in the set.

Example

let mut set = Set::new();
assert_eq!(set.len(), 0);

set.insert("x");
assert_eq!(set.len(), 1);

[src]

Removes a value from the set. Returns true if the value was present in the set.

Example

let mut set = Set::new();

set.insert("x");

assert!(set.remove("x"));
assert!(!set.remove("x"));
assert_eq!(set.len(), 0);

[src]

Reserves capacity for at least additional more elements to be inserted in the Set. The collection may reserve more space to avoid frequent reallocations.

Note

This method has yet to be fully implemented in the ordermap crate.

Example

let mut set = Set::<String>::new();
set.reserve(10);

Trait Implementations

impl<T: Clone + Eq + Hash> Clone for Set<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Eq + Eq + Hash> Eq for Set<T>
[src]

impl<T: PartialEq + Eq + Hash> PartialEq for Set<T>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl<T: Debug + Eq + Hash> Debug for Set<T>
[src]

[src]

Formats the value using the given formatter.

impl<T: Eq + Hash> Default for Set<T>
[src]

[src]

Returns the "default value" for a type. Read more

impl<T: Eq + Hash> Extend<T> for Set<T>
[src]

[src]

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

impl<T: Eq + Hash> FromIterator<T> for Set<T>
[src]

[src]

Creates a value from an iterator. Read more

impl<T, E> FromStr for Set<T> where
    T: Eq + FromStr<Err = E> + Hash,
    E: Into<Error>, 
[src]

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more

impl<T: Eq + Hash> IntoIterator for Set<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<'a, T: Eq + Hash> IntoIterator for &'a Set<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<'de, T> Deserialize<'de> for Set<T> where
    T: Deserialize<'de> + Eq + Hash + 'de, 
[src]

[src]

Deserialize this value from the given Serde deserializer. Read more

impl<T: Eq + Hash + Serialize> Serialize for Set<T>
[src]

[src]

Serialize this value into the given Serde serializer. Read more

impl<T: Eq + Hash + Stringify> Stringify for Set<T>
[src]

[src]

Returns the string representation of the give value as a byte vector. Read more

[src]

Returns the string representation of the given value. Read more