std-method

Integer saturating_mul and saturating_pow

Cap growth at the numeric boundary when that is the intended model. Expected stdout (not executed): 255 255 Common mistake: Assuming the maximum is always your application-specific cap.

Formal Syntax & Structure

rust syntaxrust
x.saturating_mul(y); x.saturating_pow(exp)

Working Example

Example Snippetrust
fn main() {    println!("{} {}", 30u8.saturating_mul(10), 3u8.saturating_pow(6));}
Rust Reference