Function core::intrinsics::cttz [−][src]
pub extern "rust-intrinsic" fn cttz<T: Copy>(x: T) -> T🔬 This is a nightly-only experimental API. (core_intrinsics)
intrinsics are unlikely to ever be stabilized, instead they should be used through stabilized interfaces in the rest of the standard library
Expand description
返回整数类型 T 的尾随未设置位 (zeroes) 的数量。
请注意,与大多数内部函数不同,这对调用是安全的;
它不需要 unsafe 块。
因此,实现不得要求用户维护任何安全不变量。
可通过 trailing_zeros 方法在整数原语上使用此内部函数的稳定版本。
Examples
#![feature(core_intrinsics)]
use std::intrinsics::cttz;
let x = 0b0011_1000_u8;
let num_trailing = cttz(x);
assert_eq!(num_trailing, 3);Run值为 0 的 x 将返回 T 的位宽:
#![feature(core_intrinsics)]
use std::intrinsics::cttz;
let x = 0u16;
let num_trailing = cttz(x);
assert_eq!(num_trailing, 16);Run