Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Handle overflow and underflow - saturating

fn main() {
    let mut num: i8 = 126;
    println!("{num}");

    num = num.saturating_add(1);
    println!("{num}");

    num = num.saturating_add(1);
    println!("{num}");
}
126
127
127