std-type

Saturating<T>

Use a numeric wrapper when supported arithmetic should stop at the integer endpoints. The wrapper expresses this policy in the type. Expected stdout (not executed): 255 Common mistake: Expecting the wrapper to impose an arbitrary business limit instead of a type limit.

Formal Syntax & Structure

rust syntaxrust
Saturating(value) + Saturating(other)

Working Example

Example Snippetrust
fn main() {    use std::num::Saturating;    let mut level = Saturating(248u8);    level += Saturating(10);    println!("{}", level.0);}
Rust Reference