Struct table::Table[][src]

pub struct Table<'a> { /* fields omitted */ }

An unordered collection of key-value pairs.

Methods

impl<'a> Table<'a>
[src]

Constructs an empty table.

Examples

use table::Table;

let table = Table::new();
assert!(table.is_empty());

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"));

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);

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());

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());

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"));

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));

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"));

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")));

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>

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>

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]

Performs the conversion.

impl<'a> From<Table<'a>> for Value<'a>
[src]

Performs the conversion.

impl<'a> TryAsRef<Table<'a>> for Value<'a>
[src]

Attempt to unwrap the inner reference.

impl<'a> TryAsMut<Table<'a>> for Value<'a>
[src]

Attempt to unwrap the inner reference.

impl<'a> Serialize for Table<'a>
[src]

Serialize this value into the given Serde serializer. Read more

impl<'de> Deserialize<'de> for Table<'de>
[src]

Deserialize this value from the given Serde deserializer. Read more

impl<'a, 'b> IntoIterator for &'b Table<'a>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a, 'b> IntoIterator for &'b mut Table<'a>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a> IntoIterator for Table<'a>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

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]

Creates a value from an iterator. Read more

impl<'a> Debug for Table<'a>
[src]

Formats the value using the given formatter. Read more

impl<'a> Clone for Table<'a>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> PartialEq for Table<'a>
[src]

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

This method tests for !=.

impl<'a, K> Index<K> for Table<'a> where
    Key<'a>: From<K>, 
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl<'a, K> IndexMut<K> for Table<'a> where
    Key<'a>: From<K>, 
[src]

Performs the mutable indexing (container[index]) operation.

Auto Trait Implementations

impl<'a> Send for Table<'a>

impl<'a> Sync for Table<'a>