Struct runestick::Object [−][src]
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]
String: Borrow<Q>,
Q: Hash + Eq + Ord,
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]
String: Borrow<Q>,
Q: Hash + Eq + Ord,
T: FromValue,
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]
String: Borrow<Q>,
Q: Hash + Eq + Ord,
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]
String: Borrow<Q>,
Q: Hash + Eq + Ord,
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]
String: Borrow<Q>,
Q: Hash + Eq + Ord,
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]
T: ToValue,
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>ⓘ
[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>ⓘ
[src]
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a String
.
pub fn values(&self) -> Values<'_, String, Value>ⓘ
[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>ⓘ
[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]
fn from_value(value: Value) -> Result<Self, VmError>
[src]
impl InstallWith for Object
[src]
fn install_with(_: &mut Module) -> Result<(), ContextError>
[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?
fn into_iter(self) -> Self::IntoIter
[src]
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?
fn into_iter(self) -> Self::IntoIter
[src]
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?
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
fn from_value(value: Value) -> Result<(Self::Output, Self::Guard), VmError>
[src]
unsafe fn unsafe_coerce(output: Self::Output) -> Self
[src]
impl UnsafeFromValue for &mut Object
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Object
impl !Send for Object
impl !Sync for Object
impl Unpin for Object
impl !UnwindSafe for Object
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,