#template #variables #structures #traits #derive #macro #trimmer

trimmer_derive

一个 derive 宏,允许将 Rust 结构体暴露给 trimmer 模板

1 个不稳定版本

使用旧的 Rust 2015

0.1.0 2017年12月18日

#388#structures

MIT/Apache

9KB
131

Trimmer Derive

Trimmer | 文档 | GitHub | Crate

此软件包允许派生 trimmer::Variable 特性。

示例

// 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);

许可证

根据您的选择,受以下许可证之一约束:

贡献

除非您明确声明,否则任何有意提交以包含在作品中的贡献,根据 Apache-2.0 许可证的定义,应按上述方式双许可,而无需附加条款或条件。


lib.rs:

trimmer 模板引擎的 derive 实现

Trimmer | 文档 | GitHub | Crate

此软件包允许派生 trimmer::Variable 特性。

目前它支持两种类型的结构,具有单个字段的元组结构(即新类型模式)

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

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

在这种情况下,所有变量实现的函数都将转发到封装的类型(并且它必须实现 Variable

以及具有命名模式的常规结构

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

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

在这种情况下,Point 将实现 attr 方法,解析 xy。所有字段都必须自己实现 Variable 特性。

依赖关系

~1.5MB
~41K SLoC