Struct table::Table [−][src]
pub struct Table<'a> { /* fields omitted */ }
An unordered collection of key-value pairs.
Methods
impl<'a> Table<'a>
[src]
impl<'a> Table<'a>
pub fn new() -> Table<'a>
[src]
pub fn new() -> Table<'a>
Constructs an empty table.
Examples
use table::Table; let table = Table::new(); assert!(table.is_empty());
pub fn with_map(map: HashMap<Key<'a>, Value<'a>>) -> Table<'a>
[src]
pub fn with_map(map: HashMap<Key<'a>, Value<'a>>) -> Table<'a>
Constructs a table from an existing map of key-value pairs.
Examples
use std::collections::HashMap; use table::{Key, Value, Table}; let mut map = HashMap::new(); map.insert(Key::from("foo"), Value::from("bar")); let table = Table::with_map(map); assert_eq!(table.get::<_, str>("foo"), Some("bar"));
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the number of key-value pairs contained by the table.
Examples
use table::Table; let mut table = Table::new(); assert_eq!(table.len(), 0); table.insert("foo", "bar"); table.insert("baz", 2); assert_eq!(table.len(), 2);
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns true
when the table is empty (has no entries).
Examples
use table::Table; let mut table = Table::new(); assert!(table.is_empty()); table.insert("foo", "bar"); assert!(!table.is_empty());
pub fn clear(&mut self)
[src]
pub fn clear(&mut self)
Removes all key-value pairs in the table, resetting its length to zero.
Examples
use table::Table; let mut table = Table::new(); table.insert("foo", "bar"); table.clear(); assert!(table.is_empty());
pub fn contains_key<K>(&self, key: K) -> bool where
Key<'a>: From<K>,
[src]
pub fn contains_key<K>(&self, key: K) -> bool where
Key<'a>: From<K>,
Returns true
if and only if a value is stored at the given key.
If this is true, calling self.get::<K, Value>(key)
will always
produce a Value
.
Examples
use table::Table; let mut table = Table::new(); assert!(!table.contains_key("foo")); table.insert("foo", 45); assert!(table.contains_key("foo"));
pub fn get<K, V>(&self, key: K) -> Option<&V> where
V: ?Sized,
Key<'a>: From<K>,
Value<'a>: TryAsRef<V>,
[src]
pub fn get<K, V>(&self, key: K) -> Option<&V> where
V: ?Sized,
Key<'a>: From<K>,
Value<'a>: TryAsRef<V>,
Attempts to retrieve a value and take reference to the inner value.
Calling this method with the V=Value
type parameter will not
perform the conversion, instead returning a reference to the
wrapping Value
object.
Examples
use table::Table; let mut table = Table::new(); table.insert("baz", 994); assert_eq!(table.get::<_, i64>("foo"), None); assert_eq!(table.get::<_, i64>("baz"), Some(&994));
pub fn get_mut<K, V>(&mut self, key: K) -> Option<&mut V> where
V: ?Sized,
Key<'a>: From<K>,
Value<'a>: TryAsMut<V>,
[src]
pub fn get_mut<K, V>(&mut self, key: K) -> Option<&mut V> where
V: ?Sized,
Key<'a>: From<K>,
Value<'a>: TryAsMut<V>,
Attempts to retrive a value and mutably reference the inner value.
Calling this method with the V=Value
type parameter will not perform
the conversion, instead returning a reference to the wrapping Value
object.
Examples
use table::Table; let mut table = Table::new(); table.insert("foo", "bar".to_string()); *table.get_mut("foo").unwrap() = "baz".to_string(); assert_eq!(table.get::<_, str>("foo"), Some("baz"));
pub fn insert<K, V>(&mut self, key: K, value: V) -> Option<Value<'a>> where
Key<'a>: From<K>,
Value<'a>: From<V>,
[src]
pub fn insert<K, V>(&mut self, key: K, value: V) -> Option<Value<'a>> where
Key<'a>: From<K>,
Value<'a>: From<V>,
Inserts a value at the given key index, returning any previous value that was stored there.
Examples
use table::{Value, Table}; let mut table = Table::new(); assert_eq!(table.insert("foo", "bar"), None); assert_eq!(table.insert("foo", 2), Some(Value::from("bar")));
pub fn remove<K>(&mut self, key: K) -> Option<Value<'a>> where
Key<'a>: From<K>,
[src]
pub fn remove<K>(&mut self, key: K) -> Option<Value<'a>> where
Key<'a>: From<K>,
Deletes a value at the given key index, returning any value that was previously stored there.
Examples
use table::{Value, Table}; let mut table = Table::new(); table.insert("foo", "bar"); assert_eq!(table.remove("foo"), Some(Value::from("bar"))); assert_eq!(table.remove("foo"), None);
ⓘImportant traits for Iter<'a, 'b>pub fn iter<'b>(&'b self) -> Iter<'a, 'b>
[src]
pub fn iter<'b>(&'b self) -> Iter<'a, 'b>
Returns a borrowing iterator over the key-value pairs in the table.
Examples
use table::{Key, Value, Table}; let mut table = Table::new(); table.insert("foo", "bar"); let mut iter = table.iter(); assert_eq!(iter.next(), Some((&Key::from("foo"), &Value::from("bar")))); assert_eq!(iter.next(), None);
ⓘImportant traits for IterMut<'a, 'b>pub fn iter_mut<'b>(&'b mut self) -> IterMut<'a, 'b>
[src]
pub fn iter_mut<'b>(&'b mut self) -> IterMut<'a, 'b>
Returns a mutably borrowing iterator over the key-value pairs in the table.
Examples
use table::{Key, Value, Table}; let mut table = Table::new(); table.insert("foo", "bar"); for (_key, value) in table.iter_mut() { *value = Value::from("baz"); } assert_eq!(table.get::<_, Value>("foo"), Some(&Value::from("baz")));
Trait Implementations
impl<'a> From<&'a Table<'a>> for Value<'a>
[src]
impl<'a> From<&'a Table<'a>> for Value<'a>
impl<'a> From<Table<'a>> for Value<'a>
[src]
impl<'a> From<Table<'a>> for Value<'a>
impl<'a> TryAsRef<Table<'a>> for Value<'a>
[src]
impl<'a> TryAsRef<Table<'a>> for Value<'a>
fn try_as_ref(&self) -> Option<&Table<'a>>
[src]
fn try_as_ref(&self) -> Option<&Table<'a>>
Attempt to unwrap the inner reference.
impl<'a> TryAsMut<Table<'a>> for Value<'a>
[src]
impl<'a> TryAsMut<Table<'a>> for Value<'a>
fn try_as_mut(&mut self) -> Option<&mut Table<'a>>
[src]
fn try_as_mut(&mut self) -> Option<&mut Table<'a>>
Attempt to unwrap the inner reference.
impl<'a> Serialize for Table<'a>
[src]
impl<'a> Serialize for Table<'a>
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
[src]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Deserialize<'de> for Table<'de>
[src]
impl<'de> Deserialize<'de> for Table<'de>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<'a, 'b> IntoIterator for &'b Table<'a>
[src]
impl<'a, 'b> IntoIterator for &'b Table<'a>
type Item = (&'b Key<'a>, &'b Value<'a>)
The type of the elements being iterated over.
type IntoIter = Iter<'a, 'b>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<'a, 'b> IntoIterator for &'b mut Table<'a>
[src]
impl<'a, 'b> IntoIterator for &'b mut Table<'a>
type Item = (&'b Key<'a>, &'b mut Value<'a>)
The type of the elements being iterated over.
type IntoIter = IterMut<'a, 'b>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<'a> IntoIterator for Table<'a>
[src]
impl<'a> IntoIterator for Table<'a>
type Item = (Key<'a>, Value<'a>)
The type of the elements being iterated over.
type IntoIter = IntoIter<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<'a, K, V> FromIterator<(K, V)> for Table<'a> where
Key<'a>: From<K>,
Value<'a>: From<V>,
[src]
impl<'a, K, V> FromIterator<(K, V)> for Table<'a> where
Key<'a>: From<K>,
Value<'a>: From<V>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
[src]
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
Creates a value from an iterator. Read more
impl<'a> Debug for Table<'a>
[src]
impl<'a> Debug for Table<'a>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a> Clone for Table<'a>
[src]
impl<'a> Clone for Table<'a>
fn clone(&self) -> Table<'a>
[src]
fn clone(&self) -> Table<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a> PartialEq for Table<'a>
[src]
impl<'a> PartialEq for Table<'a>
fn eq(&self, other: &Table<'a>) -> bool
[src]
fn eq(&self, other: &Table<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Table<'a>) -> bool
[src]
fn ne(&self, other: &Table<'a>) -> bool
This method tests for !=
.
impl<'a, K> Index<K> for Table<'a> where
Key<'a>: From<K>,
[src]
impl<'a, K> Index<K> for Table<'a> where
Key<'a>: From<K>,
type Output = Value<'a>
The returned type after indexing.
fn index(&self, index: K) -> &Self::Output
[src]
fn index(&self, index: K) -> &Self::Output
Performs the indexing (container[index]
) operation.
impl<'a, K> IndexMut<K> for Table<'a> where
Key<'a>: From<K>,
[src]
impl<'a, K> IndexMut<K> for Table<'a> where
Key<'a>: From<K>,