Struct bones_schema::alloc::SMap

source ·
pub struct SMap<K: HasSchema, V: HasSchema> { /* private fields */ }
Expand description

Typed version of a SchemaMap.

This works essentially like a [HashMap], but is compatible with the schema ecosystem.

It is also slightly more efficient to access an SMap compared to a SchemaMap because it doesn’t need to do a runtime schema check every time the map is accessed.

Implementations§

source§

impl<K: HasSchema, V: HasSchema> SMap<K, V>

source

pub fn new() -> Self

Initialize the SMap.

source

pub fn insert(&mut self, k: K, v: V) -> Option<V>

Insert an entry into the map, returning the previous value, if it exists.

source

pub fn get(&self, key: &K) -> Option<&V>

Get a reference to an item in the map.

source

pub fn get_mut(&mut self, key: &K) -> Option<&mut V>

Get a mutable reference to an item in the map.

source

pub fn remove(&mut self, key: &K) -> Option<V>

Remove an item from the map.

source

pub fn into_schema_map(self) -> SchemaMap

Convert into an untyped SchemaMap.

source

pub fn contains_key(&self, key: &K) -> bool

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

source

pub fn len(&self) -> usize

Returns the number of elements in the map.

source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

source§

impl<K: HasSchema, V: HasSchema> SMap<K, V>

source

pub fn iter( &self, ) -> Map<Iter<'_, SchemaBox, SchemaBox>, for<'a> fn(_: (&'a SchemaBox, &'a SchemaBox)) -> (&'a K, &'a V)>

Iterate over entries in the map.

source

pub fn iter_mut( &mut self, ) -> Map<IterMut<'_, SchemaBox, SchemaBox>, for<'a> fn(_: (&'a SchemaBox, &'a mut SchemaBox)) -> (&'a K, &'a mut V)>

Iterate over entries in the map.

source

pub fn keys( &self, ) -> Map<Keys<'_, SchemaBox, SchemaBox>, for<'a> fn(_: &'a SchemaBox) -> &'a K>

Iterate over keys in the map.

source

pub fn values( &self, ) -> Map<Values<'_, SchemaBox, SchemaBox>, for<'a> fn(_: &'a SchemaBox) -> &'a V>

Iterate over values in the map.

source

pub fn values_mut( &mut self, ) -> Map<ValuesMut<'_, SchemaBox, SchemaBox>, for<'a> fn(_: &'a mut SchemaBox) -> &'a mut V>

Iterate over values in the map.

Trait Implementations§

source§

impl<K: HasSchema, V: HasSchema> Clone for SMap<K, V>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K: HasSchema + Debug, V: HasSchema + Debug> Debug for SMap<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: HasSchema, V: HasSchema> Default for SMap<K, V>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<K: HasSchema, V: HasSchema> FromIterator<(K, V)> for SMap<K, V>

source§

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<K: HasSchema, V: HasSchema> HasSchema for SMap<K, V>

source§

fn schema() -> &'static Schema

Get this type’s Schema.
source§

fn register_schema()

Register this schema with the global schema registry. Read more
source§

fn cast<T: HasSchema>(this: &Self) -> &T

Cast a reference of this type to a reference of another type with the same memory layout. Read more
source§

fn try_cast<T: HasSchema>(this: &Self) -> Result<&T, SchemaMismatchError>

Cast a reference of this type to a reference of another type with the same memory layout. Read more
source§

fn cast_mut<T: HasSchema>(this: &mut Self) -> &mut T

Cast a mutable reference of this type to a reference of another type with the same memory layout. Read more
source§

fn try_cast_mut<T: HasSchema>( this: &mut Self, ) -> Result<&mut T, SchemaMismatchError>

Cast a mutable reference of this type to a reference of another type with the same memory layout. Read more
source§

fn as_schema_ref(&self) -> SchemaRef<'_>
where Self: Sized,

Converts a reference of T to a SchemaRef
source§

fn as_schema_mut(&mut self) -> SchemaRefMut<'_>
where Self: Sized,

Converts a reference of T to a SchemaRefMut
source§

impl<K: HasSchema, V: HasSchema> Index<&K> for SMap<K, V>

§

type Output = V

The returned type after indexing.
source§

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

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

impl<K: HasSchema, V: HasSchema> IndexMut<&K> for SMap<K, V>

source§

fn index_mut(&mut self, index: &K) -> &mut Self::Output

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

impl<'a, K: HasSchema, V: HasSchema> IntoIterator for &'a SMap<K, V>

§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
§

type IntoIter = Map<Iter<'a, SchemaBox, SchemaBox>, for<'a> fn(_: (&'a SchemaBox, &'a SchemaBox)) -> (&'a K, &'a V)>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, K: HasSchema, V: HasSchema> IntoIterator for &'a mut SMap<K, V>

§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
§

type IntoIter = Map<IterMut<'a, SchemaBox, SchemaBox>, for<'a> fn(_: (&'a SchemaBox, &'a mut SchemaBox)) -> (&'a K, &'a mut V)>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for SMap<K, V>

§

impl<K, V> !RefUnwindSafe for SMap<K, V>

§

impl<K, V> Send for SMap<K, V>

§

impl<K, V> Sync for SMap<K, V>

§

impl<K, V> Unpin for SMap<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> !UnwindSafe for SMap<K, V>

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> RawClone for T
where T: Clone,

source§

unsafe fn raw_clone(src: *const c_void, dst: *mut c_void)

Write the default value of the type to the pointer. Read more
source§

fn raw_clone_cb() -> Unsafe<&'static (dyn Fn(*const c_void, *mut c_void) + Sync + Send + 'static)>

Get a callback suitable for SchemaData.
source§

impl<T> RawDefault for T
where T: Default,

source§

unsafe fn raw_default(dst: *mut c_void)

Write the default value of the type to the pointer. Read more
source§

fn raw_default_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Sync + Send + 'static)>

Get a callback suitable for SchemaData.
source§

impl<T> RawDrop for T

source§

unsafe fn raw_drop(ptr: *mut c_void)

Write the default value of the type to the pointer. Read more
source§

fn raw_drop_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Sync + Send + 'static)>

Get a callback suitable for SchemaData.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V