Trait value_trait::Mutable

source ·
pub trait Mutable: IndexMut<usize> + Value + Sized {
    // Required methods
    fn as_array_mut(&mut self) -> Option<&mut <Self as ValueAccess>::Array>;
    fn as_object_mut(&mut self) -> Option<&mut Self::Object>;

    // Provided methods
    fn insert<K, V>(
        &mut self,
        k: K,
        v: V,
    ) -> Result<Option<Self::Target>, AccessError>
       where K: Into<<Self as ValueAccess>::Key>,
             V: Into<<Self as ValueAccess>::Target>,
             <Self as ValueAccess>::Key: Hash + Eq { ... }
    fn try_insert<K, V>(&mut self, k: K, v: V) -> Option<Self::Target>
       where K: Into<<Self as ValueAccess>::Key>,
             V: Into<<Self as ValueAccess>::Target>,
             <Self as ValueAccess>::Key: Hash + Eq { ... }
    fn remove<Q>(&mut self, k: &Q) -> Result<Option<Self::Target>, AccessError>
       where <Self as ValueAccess>::Key: Borrow<Q> + Hash + Eq,
             Q: Hash + Eq + Ord + ?Sized { ... }
    fn try_remove<Q>(&mut self, k: &Q) -> Option<Self::Target>
       where <Self as ValueAccess>::Key: Borrow<Q> + Hash + Eq,
             Q: Hash + Eq + Ord + ?Sized { ... }
    fn push<V>(&mut self, v: V) -> Result<(), AccessError>
       where V: Into<<Self as ValueAccess>::Target> { ... }
    fn try_push<V>(&mut self, v: V)
       where V: Into<<Self as ValueAccess>::Target> { ... }
    fn pop(&mut self) -> Result<Option<Self::Target>, AccessError> { ... }
    fn try_pop(&mut self) -> Option<Self::Target> { ... }
    fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut Self::Target>
       where <Self as ValueAccess>::Key: Borrow<Q> + Hash + Eq,
             Q: Hash + Eq + Ord + ?Sized { ... }
    fn get_idx_mut(&mut self, i: usize) -> Option<&mut Self::Target> { ... }
}
Expand description

Mutatability for values

Required Methods§

source

fn as_array_mut(&mut self) -> Option<&mut <Self as ValueAccess>::Array>

Tries to represent the value as an array and returns a mutable refference to it

source

fn as_object_mut(&mut self) -> Option<&mut Self::Object>

Tries to represent the value as an object and returns a mutable refference to it

Provided Methods§

source

fn insert<K, V>( &mut self, k: K, v: V, ) -> Result<Option<Self::Target>, AccessError>
where K: Into<<Self as ValueAccess>::Key>, V: Into<<Self as ValueAccess>::Target>, <Self as ValueAccess>::Key: Hash + Eq,

Insert into this Value as an Object. Will return an AccessError::NotAnObject if called on a Value that isn’t an object - otherwise will behave the same as HashMap::insert

§Errors

Will return Err if self is not an object.

source

fn try_insert<K, V>(&mut self, k: K, v: V) -> Option<Self::Target>
where K: Into<<Self as ValueAccess>::Key>, V: Into<<Self as ValueAccess>::Target>, <Self as ValueAccess>::Key: Hash + Eq,

Tries to insert into this Value as an Object. If the Value isn’t an object this opoeration will return None and have no effect.

source

fn remove<Q>(&mut self, k: &Q) -> Result<Option<Self::Target>, AccessError>
where <Self as ValueAccess>::Key: Borrow<Q> + Hash + Eq, Q: Hash + Eq + Ord + ?Sized,

Remove from this Value as an Object. Will return an AccessError::NotAnObject if called on a Value that isn’t an object - otherwise will behave the same as HashMap::remove

§Errors

Will return Err if self is not an Object.

source

fn try_remove<Q>(&mut self, k: &Q) -> Option<Self::Target>
where <Self as ValueAccess>::Key: Borrow<Q> + Hash + Eq, Q: Hash + Eq + Ord + ?Sized,

Tries to remove from this Value as an Object. If the Value isn’t an object this opoeration will return None and have no effect.

source

fn push<V>(&mut self, v: V) -> Result<(), AccessError>
where V: Into<<Self as ValueAccess>::Target>,

Pushes to this Value as an Array. Will return an AccessError::NotAnArray if called on a Value that isn’t an Array - otherwise will behave the same as Vec::push

§Errors

Will return Err if self is not an array.

source

fn try_push<V>(&mut self, v: V)
where V: Into<<Self as ValueAccess>::Target>,

Tries to push to a Value if as an Array. This funciton will have no effect if Value is of a different type

source

fn pop(&mut self) -> Result<Option<Self::Target>, AccessError>

Pops from this Value as an Array. Will return an AccessError::NotAnArray if called on a Value that isn’t an Array - otherwise will behave the same as Vec::pop

§Errors

Will return Err if self is not an array.

source

fn try_pop(&mut self) -> Option<Self::Target>

Tries to pop from a Value as an Array. if the Value is any other type None will always be returned

source

fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut Self::Target>
where <Self as ValueAccess>::Key: Borrow<Q> + Hash + Eq, Q: Hash + Eq + Ord + ?Sized,

Same as get but returns a mutable ref instead

source

fn get_idx_mut(&mut self, i: usize) -> Option<&mut Self::Target>

Same as get_idx but returns a mutable ref instead

Object Safety§

This trait is not object safe.

Implementors§