macro trimmer_derive

A derive macro that allows to expose rust structures to trimmer template

1 unstable release

Uses old Rust 2015

0.1.0 Dec 18, 2017

#240 in #template-engine

MIT/Apache

9KB
131 lines

Trimmer Derive

Trimmer | Docs | Github | Crate

This crate allows to derive trimmer::Variable trait.

Examples:

// Derives `.x` and `.y` attributes
#[derive(Variable)]
struct Point {
    x: u32,
    y: u32,
}

// Forwards all methods to the internal type
#[derive(Variable)]
struct NewType(SomeVarType);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Derive implementation for trimmer template engine

Trimmer | Docs | Github | Crate

This crate allows to derive trimmer::Variable trait.

Currently it supports two kinds of structures, a tuple structure with a single field (i.e. a newtype pattern):

extern crate trimmer;
#[macro_use] extern crate trimmer_derive;

#[derive(Debug, Variable)]
struct Variable(String);

In this case, all methods of the variable implementation will be forwarded to the enclosed type (and it must implement Variable)

And for regular structures with named patterns:

extern crate trimmer;
#[macro_use] extern crate trimmer_derive;

#[derive(Debug, Variable)]
struct Point {
    x: u32,
    y: u32,
}

In this case, Point will implement attr method resolving x and y. All fields must implement Variable trait themselves.

Dependencies

~2MB
~42K SLoC