Trait num_traits::ops::checked::CheckedShl
source · [−]pub trait CheckedShl: Sized + Shl<u32, Output = Self> {
fn checked_shl(&self, rhs: u32) -> Option<Self>;
}
Expand description
Performs a left shift that returns None
on shifts larger than
the type width.
Required Methods
fn checked_shl(&self, rhs: u32) -> Option<Self>
fn checked_shl(&self, rhs: u32) -> Option<Self>
Checked shift left. Computes self << rhs
, returning None
if rhs
is larger than or equal to the number of bits in self
.
use num_traits::CheckedShl;
let x: u16 = 0x0001;
assert_eq!(CheckedShl::checked_shl(&x, 0), Some(0x0001));
assert_eq!(CheckedShl::checked_shl(&x, 1), Some(0x0002));
assert_eq!(CheckedShl::checked_shl(&x, 15), Some(0x8000));
assert_eq!(CheckedShl::checked_shl(&x, 16), None);