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 日

#2535Rust 模式

Download history 8/week @ 2024-02-25 1/week @ 2024-03-03 86/week @ 2024-03-31

每月 86 次下载
units 中使用

MIT/Apache

28KB
444

tylar crates.io 构建状态

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-2.0 许可证的定义,将按上述方式双许可,没有额外的条款或条件。

无运行时依赖

功能