6 个版本
使用旧的 Rust 2015
0.2.2 | 2016 年 1 月 11 日 |
---|---|
0.2.1 | 2016 年 1 月 8 日 |
0.2.0 | 2015 年 5 月 29 日 |
0.1.2 | 2015 年 5 月 28 日 |
#2535 在 Rust 模式 中
每月 86 次下载
在 units 中使用
28KB
444 行
tylar

Type-Level Arithmetic in Rust.
支持类型级别整数的加、减、乘、除运算。
受 Björn Buckwalter 的 Haskell 库 numtype 的启发。由于多分派和相关类型,将其引入 Rust。
* 范围为(–50,50)的数字应该基本正常工作,具体取决于操作。类型检查可能会比较慢。
示例
// N2 is the type for -2, P5 is +5, Out is the result type
// of the addition; new() creates a new instance (actually a
// no-op, since the types are zero-sized) and into() turns
// the object into an integer value, computed at compile-time
// due to static dispatch.
let result: i32 = <N2 as Add<_,P5>>::Out::new().into();
println!("-2 + 5 = {}", result); // prints `-2 + 5 = 3`
更多内容请参阅 examples/basics.rs 并运行 cargo run --example basics
。
不幸的是,这些示例(因此也包括 cargo test
)在 Rust 1.0 中无法工作,但 tylar 本身与 Rust 1.0 兼容且可用。
许可协议
根据您的选择,许可协议为
- 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 许可证的定义,将按上述方式双许可,没有额外的条款或条件。