#u16 #numbers #checking #performance #unsigned #specialized #odd

is-even-u16

针对 u16 数字的专业化 is-even 检查

3 个稳定版本

1.0.2 2024 年 3 月 7 日

#1#odd

MIT 许可证

5.5MB
262K SLoC

is-even-u16

Rust 的典型 is-even 检查

该包专门针对无符号 16 位数字,出于性能考虑。

用法

运行 cargo add is_even_u16,然后在你的 src/main.rs 中进行如下操作

use is_even_u16::is_even_u16;

fn main() {
    println!("7 is even? {}", if is_even_u16(7) { "yes" } else { "no" });
}

你甚至可以使用 Rust 之神提供的布尔取反操作符来检查一个数字是否为奇数!

这里

use is_even_u16::is_even_u16;

fn main() {
    println!("7 is odd? {}", if !is_even_u16(7) { "yes" } else { "no" });
}

许可证

The MIT License

Copyright (c) 2024 RGBCube

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDEDAS IS, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

无运行时依赖