Satint: saturating integer types
โ Rust ๐ 2026-05-05 ๐ค surdeus ๐๏ธ 2Hi all! I just published my first crate that offers saturating integer types together with conversions to/from primitive integers. I would be more than happy to have some feedback on it. I tried my best to make it as idiomatic as possible.
It never panics (except for division/remainder by zero if the panicking-ops feature is explicitly enabled), is no_std compatible, doesn't allocate, and doesn't use any unsafe code.
The crate: crates.io: Rust Package Registry
Repository: GitHub - Jmgr/satint: Saturating integers ยท GitHub
Documentation: satint - Rust
All the new types wrap core::num::Saturating. It introduces a new trait, SaturatingFrom (similar to what the saturating_cast crate does) and implements it for all integer types, as well as for the wrapper types.
The idea is to make it as transparent and easy as possible to do saturating operations without having to remember to call saturating_add, saturating_sub, etc.
A few examples:
use satint::{SaturatingInto, Si8, Su8, si8, su8};
assert_eq!(Su8::MAX + 1, Su8::MAX);
assert_eq!(su8(0) - 1, Su8::ZERO);
assert_eq!(si8(120) + su8(20), Si8::MAX); // clamps to the left hand side
let value: Su8 = 999_u16.saturating_into();
assert_eq!(value, Su8::MAX);
Disclaimer: I used LLM agents to generate documentation, examples and some tests; I did not use them to write the core of the library, and only asked them to provide feedback, find typos and bugs. All potential bugs will be my own responsibility and will haunt me forever ![]()
3 posts - 2 participants
๐ท๏ธ Rust_feed