Struct typemap_core::Ty [−][src]
A type-level linked-list implementation of a typemap
The generic arguments can be treated as if this were a cons cell. i.e.
use typemap_core::{Ty, TyEnd}; type Example = Ty<u32, Ty<u16, Ty<u8, TyEnd>>>;
is akin to (cons u32 (cons u16 (cons u8 nil)))
at the type level,
and creates a storage capable of holding a u32, a u16, and a u8.
A couple of helper macros, typemap_ty!
and typemap!
exist, for ease of definition.
use typemap_core::{typemap, typemap_ty}; type Example = typemap_ty!(u32, u16, u8); let example: Example = typemap!(u32 = 0u32, u16 = 1337u16, u8 = 255u8);
As a linked list, it is fairly easy to prepend additional items:
let extended = typemap!(&str = "Hello!", ..example);
Which also allows you to "override" existing values temporarilly.
use typemap_core::{typemap, TypeMapGet}; let greeting_options = typemap!(&str = "Hello!"); let rude_greeting = typemap!(&str = "Go away.", ..&greeting_options); assert_eq!(rude_greeting.get::<&str>(), &"Go away."); drop(rude_greeting); assert_eq!(greeting_options.get::<&str>(), &"Hello!");
See the TypeMapGet
and TypeMapSet
traits for more details.
Implementations
impl<V: 'static, R> Ty<V, R>
[src]
Trait Implementations
impl<V: Clone + 'static, R: Clone> Clone for Ty<V, R>
[src]
fn clone(&self) -> Ty<V, R>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A: 'static, R: TypeMapGet> Contains<A> for Ty<A, R>
[src]
impl<A: 'static, B: 'static, R: TypeMapGet> Contains<A> for &Ty<B, R> where
Ty<B, R>: Contains<A>,
[src]
Ty<B, R>: Contains<A>,
impl<A: 'static, B: 'static, R: TypeMapGet> Contains<A> for &mut Ty<B, R> where
Ty<B, R>: Contains<A>,
[src]
Ty<B, R>: Contains<A>,
impl<A: 'static, B: 'static, R: Contains<B>> Contains<B> for Ty<A, R>
[src]
impl<A: 'static, R: TypeMapSet> ContainsMut<A> for Ty<A, R>
[src]
impl<A: 'static, B: 'static, R: TypeMapSet> ContainsMut<A> for &mut Ty<B, R> where
Ty<B, R>: TypeMapSet + ContainsMut<A>,
[src]
Ty<B, R>: TypeMapSet + ContainsMut<A>,
impl<A: 'static, B: 'static, R: ContainsMut<B>> ContainsMut<B> for Ty<A, R>
[src]
impl<V: Copy + 'static, R: Copy> Copy for Ty<V, R>
[src]
impl<V: Debug + 'static, R: Debug> Debug for Ty<V, R>
[src]
impl<V: Default + 'static, R: Default> Default for Ty<V, R>
[src]
impl<V: Eq + 'static, R: Eq> Eq for Ty<V, R>
[src]
impl<V: PartialEq + 'static, R: PartialEq> PartialEq<Ty<V, R>> for Ty<V, R>
[src]
impl<V: 'static, R> StructuralEq for Ty<V, R>
[src]
impl<V: 'static, R> StructuralPartialEq for Ty<V, R>
[src]
impl<V: 'static, R: TypeMapGet> TypeMapGet for Ty<V, R>
[src]
fn try_get<T: 'static>(&self) -> Option<&T>
[src]
fn get<T: 'static>(&self) -> &T where
Self: Contains<T>,
[src]
Self: Contains<T>,
impl<V: 'static, R: TypeMapGet> TypeMapGet for &Ty<V, R>
[src]
fn try_get<T: 'static>(&self) -> Option<&T>
[src]
fn get<T: 'static>(&self) -> &T where
Self: Contains<T>,
[src]
Self: Contains<T>,
impl<V: 'static, R: TypeMapGet> TypeMapGet for &mut Ty<V, R>
[src]
fn try_get<T: 'static>(&self) -> Option<&T>
[src]
fn get<T: 'static>(&self) -> &T where
Self: Contains<T>,
[src]
Self: Contains<T>,
impl<V: 'static, R: TypeMapSet> TypeMapSet for &Ty<V, R>
[src]
fn try_set<T: 'static>(&mut self, _value: T) -> bool
[src]
fn set<T: 'static>(&mut self, value: T) where
Self: ContainsMut<T>,
[src]
Self: ContainsMut<T>,
impl<V: 'static, R: TypeMapSet> TypeMapSet for Ty<V, R>
[src]
fn try_set<T: 'static>(&mut self, value: T) -> bool
[src]
fn set<T: 'static>(&mut self, value: T) where
Self: ContainsMut<T>,
[src]
Self: ContainsMut<T>,
impl<V: 'static, R: TypeMapSet> TypeMapSet for &mut Ty<V, R>
[src]
fn try_set<T: 'static>(&mut self, value: T) -> bool
[src]
fn set<T: 'static>(&mut self, value: T) where
Self: ContainsMut<T>,
[src]
Self: ContainsMut<T>,
Auto Trait Implementations
impl<V, R> Send for Ty<V, R> where
R: Send,
V: Send,
[src]
R: Send,
V: Send,
impl<V, R> Sync for Ty<V, R> where
R: Sync,
V: Sync,
[src]
R: Sync,
V: Sync,
impl<V, R> Unpin for Ty<V, R> where
R: Unpin,
V: Unpin,
[src]
R: Unpin,
V: Unpin,
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, 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>,