# int-cast
This Rust crate provides convenient casts between primitive integers. The casts
provided are:
- `x.cast()`, only implemented when the cast is infallible,
- `x.checked_cast()`, returning `None` if the cast fails,
- `x.strict_cast()`, panicking if the cast fails,
- `x.unchecked_cast()`, undefined behavior if the cast fails,
- `x.wrapping_cast()`, never fails, wraps around, and
- `x.saturating_cast()`, never fails, saturates at the boundary.
Unlike `x.into()` and `x.try_into()` these casts can only convert between
primitive integer types, and they support directly writing the target type using
a turbofish, e.g. `x.strict_cast::<usize>()`.
To start using `int-cast` add the following to your `Cargo.toml`:
[dependencies]
int-cast = "0.1"
Then add `use int_cast::IntCast;` to import the extension trait. Please refer to
[the documentation](https://docs.rs/int-cast) for more information on usage.
## License
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
at your option.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.