[−][src]Struct simrs::Key
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]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[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]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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,
V: RefUnwindSafe,
impl<V> Send for Key<V> where
V: Send,
V: Send,
impl<V> Sync for Key<V> where
V: Sync,
V: Sync,
impl<V> Unpin for Key<V> where
V: Unpin,
V: Unpin,
impl<V> UnwindSafe for Key<V> where
V: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,