[][src]Struct simrs::Key

pub struct Key<V> { /* fields omitted */ }

A type-safe key used to fetch values from the value store.

Construction

A key can be constructed only by calling State::insert. The state assigns a new numerical ID to the inserted value, which is unique throughout the running of the program. This ensures type safety, as explained below.

Type Safety

These keys are type-safe in a sense that a key used to insert a value of type T cannot be used to access a value of another type U. An attempt to do so will result in a compile error. It is achieved by having the key generic over T. However, T is just a marker, and no values of type T are stored internally.

This example deliberately fails to compile
let mut state = State::default();
let id = state.insert(String::from("1"));
let _: Option<i32> = state.remove(id);  // Error!
let _ = state.remove::<i32>(id);        // Error!

Trait Implementations

impl<T> Clone for Key<T>[src]

impl<T> Copy for Key<T>[src]

impl<V: Debug> Debug for Key<V>[src]

impl<V: Eq> Eq for Key<V>[src]

impl<V: Hash> Hash for Key<V>[src]

impl<V: PartialEq> PartialEq<Key<V>> for Key<V>[src]

impl<V> StructuralEq for Key<V>[src]

impl<V> StructuralPartialEq for Key<V>[src]

Auto Trait Implementations

impl<V> RefUnwindSafe for Key<V> where
    V: RefUnwindSafe

impl<V> Send for Key<V> where
    V: Send

impl<V> Sync for Key<V> where
    V: Sync

impl<V> Unpin for Key<V> where
    V: Unpin

impl<V> UnwindSafe for Key<V> where
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.