Struct bones_ecs::prelude::SMap

pub struct SMap<K, V>
where 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§

§

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

pub fn new() -> SMap<K, V>

Initialize the SMap.

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

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

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

Get a reference to an item in the map.

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

Get a mutable reference to an item in the map.

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

Remove an item from the map.

pub fn into_schema_map(self) -> SchemaMap

Convert into an untyped SchemaMap.

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

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

pub fn len(&self) -> usize

Returns the number of elements in the map.

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

§

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

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.

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.

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

Iterate over keys in the map.

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

Iterate over values in the map.

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§

§

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

§

fn clone(&self) -> SMap<K, V>

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
§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

fn default() -> SMap<K, V>

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

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

§

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

Creates a value from an iterator. Read more
§

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

§

fn schema() -> &'static Schema

Get this type’s [Schema].
§

fn register_schema()

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

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

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

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

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

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

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

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

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

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

Converts a reference of T to a SchemaRef
§

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

Converts a reference of T to a SchemaRefMut
§

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

§

type Output = V

The returned type after indexing.
§

fn index(&self, index: &K) -> &<SMap<K, V> as Index<&K>>::Output

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

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

§

fn index_mut(&mut self, index: &K) -> &mut <SMap<K, V> as Index<&K>>::Output

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

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

§

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

fn into_iter(self) -> <&'a SMap<K, V> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

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

§

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

fn into_iter(self) -> <&'a mut SMap<K, V> as IntoIterator>::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> FromWorld for T
where T: Default,

source§

fn from_world(_world: &World) -> T

Creates Self using data from the given World.
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.

§

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

§

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

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

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

Get a callback suitable for [SchemaData].
§

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

§

unsafe fn raw_default(dst: *mut c_void)

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

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

Get a callback suitable for [SchemaData].
§

impl<T> RawDrop for T

§

unsafe fn raw_drop(ptr: *mut c_void)

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

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

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