1 个不稳定版本
使用旧的 Rust 2015
0.1.0 | 2017年12月18日 |
---|
#388 在 #structures
9KB
131 行
Trimmer Derive
此软件包允许派生 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 License 2.0版本(./LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证(./LICENSE-MIT 或 http://opensource.org/licenses/MIT)
。
贡献
除非您明确声明,否则任何有意提交以包含在作品中的贡献,根据 Apache-2.0 许可证的定义,应按上述方式双许可,而无需附加条款或条件。
lib.rs
:
trimmer 模板引擎的 derive 实现
此软件包允许派生 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
方法,解析 x
和 y
。所有字段都必须自己实现 Variable
特性。
依赖关系
~1.5MB
~41K SLoC