std-module

std::num

Use numeric helper types to express an invariant or choose an arithmetic policy. Primitive integer methods remain available directly on numbers. Expected stdout (not executed): 3 4 255 Common mistake: Looking for every integer operation as a free function in this module.

Formal Syntax & Structure

rust syntaxrust
use std::num::{NonZeroU8, Wrapping, Saturating};

Working Example

Example Snippetrust
fn main() {    use std::num::{NonZeroU8, Wrapping, Saturating};    let count = NonZeroU8::new(3).unwrap();    println!("{} {} {}", count.get(), (Wrapping(250u8) + Wrapping(10)).0, (Saturating(250u8) + Saturating(10)).0);}
Rust Reference