当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust u64.checked_next_multiple_of用法及代码示例


本文简要介绍rust语言中 u64.checked_next_multiple_of 的用法。

用法

pub const fn checked_next_multiple_of(self, rhs: u64) -> Option<u64>

计算大于或等于 self 的最小值,它是 rhs 的倍数。返回 None is rhs 为零,否则操作将导致溢出。

例子

基本用法:

#![feature(int_roundings)]
assert_eq!(16_u64.checked_next_multiple_of(8), Some(16));
assert_eq!(23_u64.checked_next_multiple_of(8), Some(24));
assert_eq!(1_u64.checked_next_multiple_of(0), None);
assert_eq!(u64::MAX.checked_next_multiple_of(2), None);

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 u64.checked_next_multiple_of。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。