slr_config::slr_def! [] [src]

macro_rules! slr_def {
    (
		$(#[$attrs:meta])*
		pub struct $name: ident
		{
			$(pub $field_name: ident : $field_type: ty = $field_init: expr),* $(,)*
		}
	) => { ... };
    (
		$(#[$attrs:meta])*
		struct $name: ident
		{
			$($field_name: ident : $field_type: ty = $field_init: expr),* $(,)*
		}
	) => { ... };
    (
		$(#[$attrs:meta])*
		enum $name: ident
		{
			$($var_name: ident),* $(,)*
		}
	) => { ... };
    (
		$(#[$attrs:meta])*
		pub enum $name: ident
		{
			$($var_name: ident),* $(,)*
		}
	) => { ... };
}

A macro to define the compile-time schemas for configuration elements. You can use this macro to define structs and enums, like so:

#[macro_use]
extern crate slr_config;

slr_def!
{
    #[derive(Clone)] // Attributes supported.
    pub struct TestSchema
    {
        pub key: u32 = 0, // The rhs assignments are initializer expressions.
        pub arr: Vec<u32> = vec![]
    }
}

slr_def!
{
    pub enum TestEnum
    {
        VariantA,
        VariantB
    }
}

The types declared by both invocations implement ElementRepr, and the struct versions also implement a new constructor which creates the type with the default value specified by the macro invocation.