Struct simrs::Key

source · []
pub struct Key<V> { /* private fields */ }
Expand description

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.