Dictionary

Struct Dictionary 

Source
pub struct Dictionary { /* private fields */ }
Expand description

A key value based dictionary.

Implementations§

Source§

impl Dictionary

Source

pub fn len(&self) -> usize

The number of items in the dictionary.

Source

pub fn is_empty(&self) -> bool

Returns true if the dictionary has no items.

Source

pub fn keys(&self) -> &[KBox<Any>]

Gets a slice containing all the keys in this dictionary.

Source

pub fn values(&self) -> &[KBox<Any>]

Gets a slice containing all the values in this dictionary.

Source

pub fn insert(&mut self, key: impl Into<KBox<Any>>, value: impl Into<KBox<Any>>)

Insert a specified key and value at the end of the dictionary. No checks are done on uniqueness so duplicates are possible.

Examples found in repository?
examples/using_dictionaries.rs (line 8)
4fn main() {
5    //Symbols use a lot of try_into. Sad.
6    let mut dict = KBox::new_dict();
7
8    dict.insert(symbol("One"), 1i32);
9    dict.insert(symbol("Two"), 2i32);
10    dict.insert(symbol("Three"), 3i32);
11
12    println!("{:?}", cast!(&dict[symbol("Two")]; Atom<Symbol>));
13}
Source

pub fn get<T: Into<KBox<Any>>>(&self, key: T) -> Option<&KBox<Any>>

Gets a value by key. Note that KDB dictionaries are treated as unordered and hence this is an O(n) operation.

Source

pub fn iter(&self) -> impl Iterator<Item = (&KBox<Any>, &KBox<Any>)>

An iterator through every value in the KDB object

Trait Implementations§

Source§

impl AsRef<Any> for Dictionary

Source§

fn as_ref(&self) -> &Any

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

impl<T> Index<T> for Dictionary
where for<'a> T: Into<KBox<Any>>,

Source§

type Output = Any

The returned type after indexing.
Source§

fn index(&self, index: T) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

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.