| Crates.io | isotopes |
| lib.rs | isotopes |
| version | 0.6.0 |
| created_at | 2025-08-27 12:16:09.779389+00 |
| updated_at | 2025-08-31 11:39:39.791072+00 |
| description | Variants of common types for enforcing invariance. |
| homepage | https://github.com/rust-asians/isotopes |
| repository | https://github.com/rust-asians/isotopes |
| max_upload_size | |
| id | 1812514 |
| size | 15,205 |
This is currently in early development. None of the API is stable.
Variants of common types for enforcing invariance.
Types that cannot go under 0. They implement Add<Self>, Mul<Self>, and Div<Self> that just do exactly what their
underlying types do. Sub was not implemented, since underflowing is extremely easy to accidentally do.
The lack of Sub is still under consideration, since unsigned integers do implement it. However, it's still unclear
if we should follow this unsafe implementation out of consistency, or if it's worth having a wrapper around unsigned
integers that does hides Sub.
They implement the checked operator and bound traits.
UF32UF64A ratio that is between 0 and 1. They use f32/f64 under the hood. They implement
the checked operator and bound traits.
ClampedRatio32ClampedRatio64These just provide a standard way of defining the upper and lower limits of a type.
Implementations of Min and Max for primitive ints (signed and unsigned) and floats are already defined.
CheckedAddCheckedSubCheckedMulCheckedDivEach of these traits provide one function (e.g., checked_add) that lets you add two numbers and returns a Result.
You can customize the Error type.
Saturating is a wrapper struct that automatically implements the standard operator traits Add, Sub, Mul, and
Div for all implementations of the Checked* traits that also implement Min and Max. Underflowing and overflowing
the underlying type just returns its min and max values respectively.