simd_json::derived

Trait MutableObject

Source
pub trait MutableObject {
    type Key: ?Sized;
    type Target;
    type Object;

    // Required methods
    fn insert<K, V>(
        &mut self,
        k: K,
        v: V,
    ) -> Result<Option<Self::Target>, AccessError>
       where Self::Key: From<K> + Hash + Eq,
             V: Into<Self::Target>;
    fn remove<Q>(&mut self, k: &Q) -> Result<Option<Self::Target>, AccessError>
       where Self::Key: Borrow<Q>,
             Q: Hash + Eq + Ord + ?Sized;
    fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut Self::Target>
       where Self::Key: Borrow<Q>,
             Q: Hash + Eq + Ord + ?Sized;

    // Provided methods
    fn try_insert<K, V>(&mut self, k: K, v: V) -> Option<Self::Target>
       where Self::Key: From<K> + Hash + Eq,
             V: Into<Self::Target> { ... }
    fn try_remove<Q>(&mut self, k: &Q) -> Option<Self::Target>
       where Self::Key: Borrow<Q>,
             Q: Hash + Eq + Ord + ?Sized { ... }
}
Expand description

Mutatability for object like values

Required Associated Types§

Source

type Key: ?Sized

The type for Object Keys

Source

type Target

The type for Object Values

Source

type Object

The type for Objects

Required Methods§

Source

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

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 remove<Q>(&mut self, k: &Q) -> Result<Option<Self::Target>, AccessError>
where Self::Key: Borrow<Q>, 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 get_mut<Q>(&mut self, k: &Q) -> Option<&mut Self::Target>
where Self::Key: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Same as get but returns a mutable ref instead

Provided Methods§

Source

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

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 try_remove<Q>(&mut self, k: &Q) -> Option<Self::Target>
where Self::Key: Borrow<Q>, 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§