2个不稳定版本
| 新 0.2.0 | 2024年8月21日 |
|---|---|
| 0.1.0 | 2024年1月26日 |
241 在 过程宏 中
每月 155 次下载
21KB
377 行
🦀 typed-fields
你喜欢强类型结构体吗?
typed-fields 是一组宏,可以生成遵循 newtype 模式的类型。目前支持以下类型
name!- 基于字符串的类型number!- 基于数字的类型secret!- 保密类型的类型(需要secret功能)ulid!- ULIDs 的类型(需要ulid功能)url!- URLs 的类型(需要url功能)uuid!- UUIDs 的类型(需要uuid功能)
示例
以下示例展示了 number! 宏,它生成一个由 i64 支持的新类型。
use typed_fields::number;
// Define a new type that is backed by an `i64`
number!(UserId);
fn main() {
// Create a new `UserId` from an `i64`
let id = UserId::new(42);
// Common traits like `Display` are automatically implemented for the type
println!("User ID: {}", id);
}
许可证
根据以下任一许可证授权:
- Apache License 2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 https://open-source.org.cn/licenses/MIT)
供您选择。
贡献
除非您明确声明,否则根据 Apache-2.0 许可证定义,您有意提交的工作将根据上述条款进行双重许可,不附加任何其他条款或条件。
依赖项
~0.3–1.5MB
~33K SLoC