1 个不稳定版本
0.0.2 | 2024年2月9日 |
---|---|
0.0.1 |
|
0.0.0 |
|
#6 in #dec
34KB
1K SLoC
大家好!我认为 Rust 的运算符太少。所以我为 Rust 编写了一个运算符 crate 的扩展。我觉得 Rust 并不会使用它。我提供了接口以允许 Rust 中有更多功能。你有什么新想法或建议吗?请告诉我。现在是 0.0.2 版本,所以我只相信四个函数(增加、减少、弹出、移动)。你的支持是我前进的动力。
lib.rs
:
Rust 运算符的扩展。到目前为止,这个 crate 提供了四个运算符,例如 DEC(减少,等同于减 1)、INC(增加,等同于加 1)。这些运算符与一些汇编指令相同。因此你不必担心工作。例如
use ooo::inc::*; //use the trait that increase.
use ooo::ina::*; //use the trait that increase assign.
let mut x: usize = 300usize; //assign "300usize" to x.
assert_eq!(x, 300usize); //no problem.
x.inc_assign(); //add one to x when use trait "IncAssign".
assert_eq!(x, 301usize); //if you do it,should has not worings.
assert_eq!(x.inc(), 302usize); //add one again.it will be "302usize" when use trait "Inc".
assert_eq!(x, 301usize); //but you can know the variable "x" was not affected.
//because "inc" method return a new increased value and not affect self,
//"inc_assign" method affect self and do not return anything.
use ooo::dec::*; //use the trait that decrease.
use ooo::dea::*; //use the trait that decrease assign.
x.dec_assign(); //substruct one to x when use trait "DecrefAssign"
assert_eq!(x, 301usize); //no ploblem.
assert_eq!(x.dec(), 300usize); //Allow method "decrease" when use trait "Dec"
assert_eq!(x, 301usize); //But also do not affect self.
如果你有建议,欢迎告诉我。我的邮箱是 "ora_in_py@hotmail.com"。