[][src]Struct runestick::Object

#[repr(transparent)]pub struct Object { /* fields omitted */ }

Struct representing a dynamic anonymous object.

Examples

let mut object = runestick::Object::new();
assert!(object.is_empty());

object.insert_value(String::from("foo"), 42)?;
object.insert_value(String::from("bar"), true)?;
assert_eq!(2, object.len());

assert_eq!(Some(42), object.get_value("foo")?);
assert_eq!(Some(true), object.get_value("bar")?);
assert_eq!(None::<bool>, object.get_value("baz")?);

Implementations

impl Object[src]

pub fn new() -> Self[src]

Construct a new object.

pub fn with_capacity(_cap: usize) -> Self[src]

Construct a new object with the given capacity.

pub fn len(&self) -> usize[src]

Returns the number of elements in the object.

pub fn is_empty(&self) -> bool[src]

Returns true if the Object contains no elements.

pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&Value> where
    String: Borrow<Q>,
    Q: Hash + Eq + Ord
[src]

Returns a reference to the value corresponding to the key.

pub fn get_value<Q: ?Sized, T>(&self, k: &Q) -> Result<Option<T>, VmError> where
    String: Borrow<Q>,
    Q: Hash + Eq + Ord,
    T: FromValue
[src]

Get the given value at the given index.

pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut Value> where
    String: Borrow<Q>,
    Q: Hash + Eq + Ord
[src]

Returns a mutable reference to the value corresponding to the key.

pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool where
    String: Borrow<Q>,
    Q: Hash + Eq + Ord
[src]

Returns true if the map contains a value for the specified key.

pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<Value> where
    String: Borrow<Q>,
    Q: Hash + Eq + Ord
[src]

Removes a key from the object, returning the value at the key if the key was previously in the object.

pub fn insert_value<T>(&mut self, k: String, v: T) -> Result<(), VmError> where
    T: ToValue
[src]

Inserts a key-value pair into the dynamic object, converting it as necessary through the ToValue trait.

pub fn insert(&mut self, k: String, v: Value) -> Option<Value>[src]

Inserts a key-value pair into the dynamic object.

pub fn clear(&mut self)[src]

Clears the object, removing all key-value pairs. Keeps the allocated memory for reuse.

pub fn into_inner(self) -> BTreeMap<String, Value>[src]

Convert into inner.

pub fn iter(&self) -> Iter<'_, String, Value>

Notable traits for Iter<'a, K, V>

impl<'a, K, V> Iterator for Iter<'a, K, V> where
    V: 'a,
    K: 'a, 
type Item = (&'a K, &'a V);
[src]

An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (&'a String, &'a Value).

pub fn keys(&self) -> Keys<'_, String, Value>

Notable traits for Keys<'a, K, V>

impl<'a, K, V> Iterator for Keys<'a, K, V> type Item = &'a K;
[src]

An iterator visiting all keys in arbitrary order. The iterator element type is &'a String.

pub fn values(&self) -> Values<'_, String, Value>

Notable traits for Values<'a, K, V>

impl<'a, K, V> Iterator for Values<'a, K, V> type Item = &'a V;
[src]

An iterator visiting all values in arbitrary order. The iterator element type is &'a Value.

pub fn iter_mut(&mut self) -> IterMut<'_, String, Value>

Notable traits for IterMut<'a, K, V>

impl<'a, K, V> Iterator for IterMut<'a, K, V> where
    V: 'a,
    K: 'a, 
type Item = (&'a K, &'a mut V);
[src]

An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values. The iterator element type is (&'a String, &'a mut Value).

pub fn into_iterator(&self) -> Iterator[src]

Convert into a runestick iterator.

Trait Implementations

impl Clone for Object[src]

impl Debug for Object[src]

impl Default for Object[src]

impl From<Object> for Value[src]

impl FromIterator<(String, Value)> for Object[src]

impl FromValue for Object[src]

impl InstallWith for Object[src]

impl<'a> IntoIterator for &'a Object[src]

type Item = (&'a String, &'a Value)

The type of the elements being iterated over.

type IntoIter = Iter<'a, String, Value>

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a mut Object[src]

type Item = (&'a String, &'a mut Value)

The type of the elements being iterated over.

type IntoIter = IterMut<'a, String, Value>

Which kind of iterator are we turning this into?

impl IntoIterator for Object[src]

type Item = (String, Value)

The type of the elements being iterated over.

type IntoIter = IntoIter<String, Value>

Which kind of iterator are we turning this into?

pub fn into_iter(self) -> Self::IntoIter[src]

Creates a consuming iterator, that is, one that moves each key-value pair out of the object in arbitrary order. The object cannot be used after calling this.

impl Named for Object[src]

impl ToValue for Object[src]

impl TypeOf for Object[src]

impl UnsafeFromValue for &Object[src]

type Output = *const Object

The output type from the unsafe coercion.

type Guard = RawRef

The raw guard returned. Read more

impl UnsafeFromValue for &mut Object[src]

type Output = *mut Object

The output type from the unsafe coercion.

type Guard = RawMut

The raw guard returned. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.