Macro declarative_type_state::type_table
source · macro_rules! type_table { ( ENUM_OUT: { #[vars( $( $all_meta: meta ),* $(,)? )] $( #[$enum_meta: meta] )* $enum_vis: vis enum $enum_ident: ident { $( $( #[$var_meta: meta] )* $var_ident: ident $( ( $($var_tuple: tt)* ) )? $( { $($var_fields: tt)* } )? ),* $(,)? } } TABLE: { $( #[$table_meta: meta] )* $table_vis: vis struct $table_ident: ident $(;)? $({})? } ) => { ... }; ( ENUM_OUT: { #[vars( $( $all_meta: meta ),* $(,)? )] $( #[$enum_meta: meta] )* $enum_vis: vis enum $enum_ident: ident { $( $( #[$var_meta: meta] )* $var_ident: ident $( ( $($var_tuple: tt)* ) )? $( { $($var_fields: tt)* } )? ),* $(,)? } } TABLE: { $( #[$table_meta: meta] )* $table_vis: vis struct $table_ident: ident $(;)? $({})? } DELEGATES: { $( impl $( <[ $( $trait_gen: tt )* ]> )? trait $trait_ty: path $( where [ $( $trait_bound: tt )* ] )? { $( [ $( $item: tt )* ] )* } )* $( impl { $( [ $( $std_impl: tt )* ] )* } )? } ) => { ... }; ( ENUM_IN: $enum_ident: ident $(;)? $({})? TABLE: { $( #[$table_meta: meta] )* $table_vis: vis struct $table_ident: ident { $( $var_ident: ident: $var_ty: ty ),* $(,)? } } ) => { ... }; ( $( #[$table_meta: meta] )* $table_vis: vis struct $table_ident: ident { $( $var_ident: ident: $var_ty: ty ),* $(,)? } ) => { ... }; }
Expand description
§Generates a collection type that contains a single value of each type
The types must be unique!
For a combination of this and variant_types, see variant_types_table
§Usage
#![feature(macro_metavar_expr)]
mod table {
use declarative_type_state::type_table;
type_table! {
pub struct DurationTable {
seconds: f32,
hours: i32,
infinite: (),
}
}
}
// The values can be accessed by using `get::<T>` or `get_mut::<T>`:
let mut table = table::DurationTable::new(2.0, 5, ());
let seconds = table.get::<f32>();
let hours = table.get_mut::<i32>();§The Table also implements:
- fn iter(&self) -> Iterator<Item = Ref
> - fn iter_mut(&mut self) -> Iterator<Item = RefMut
> - fn into_iter(self) -> Iterator<Item = Owned
>
§Example
#![feature(macro_metavar_expr)]
mod table {
declarative_type_state::type_table! {
#[derive(Debug, Clone)]
pub struct DurationTable {
seconds: f32,
hours: i32,
infinite: (),
}
}
}