The snippet library.
Small, practical examples. Search by task or narrow things down below.
Check whether a floating-point value is finite
Check whether a floating-point value is finite in a complete Rust program using the standard library.
Rust✓ Tested
Clamp a number to a valid interval
Clamp a number to a valid interval in a complete Rust program using the standard library.
Rust✓ Tested
Construct an instant relative to the Unix epoch
Construct an instant relative to the Unix epoch in a complete Rust program using the standard library.
Rust✓ Tested
Express a duration in milliseconds
Express a duration in milliseconds in a complete Rust program using the standard library.
Rust✓ Tested
Reject a narrowing integer conversion
Reject a narrowing integer conversion in a complete Rust program using the standard library.
Rust✓ Tested
Round and format a decimal value
Round and format a decimal value in a complete Rust program using the standard library.
Rust✓ Tested
Saturate arithmetic at the type boundary
Saturate arithmetic at the type boundary in a complete Rust program using the standard library.
Rust✓ Tested
Subtract durations without underflow
Subtract durations without underflow in a complete Rust program using the standard library.
Rust✓ Tested
Use a nonnegative remainder for cyclic indexing
Use a nonnegative remainder for cyclic indexing in a complete Rust program using the standard library.
Rust✓ Tested