Struct typemap_core::Ty[][src]

pub struct Ty<V: 'static, R> { /* fields omitted */ }

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]

pub const fn new(val: V, rest: R) -> Self[src]

Construct a node of a typemap

Trait Implementations

impl<V: Clone + 'static, R: Clone> Clone for Ty<V, R>[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]

impl<A: 'static, B: 'static, R: TypeMapGet> Contains<A> for &mut Ty<B, R> where
    Ty<B, R>: Contains<A>, 
[src]

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]

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]

impl<V: 'static, R: TypeMapGet> TypeMapGet for &Ty<V, R>[src]

impl<V: 'static, R: TypeMapGet> TypeMapGet for &mut Ty<V, R>[src]

impl<V: 'static, R: TypeMapSet> TypeMapSet for &Ty<V, R>[src]

impl<V: 'static, R: TypeMapSet> TypeMapSet for Ty<V, R>[src]

impl<V: 'static, R: TypeMapSet> TypeMapSet for &mut Ty<V, R>[src]

Auto Trait Implementations

impl<V, R> Send for Ty<V, R> where
    R: Send,
    V: Send
[src]

impl<V, R> Sync for Ty<V, R> where
    R: Sync,
    V: Sync
[src]

impl<V, R> Unpin for Ty<V, R> where
    R: Unpin,
    V: Unpin
[src]

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, 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.