int-cast 0.1.0

Convenient casts between primitive integers.
Documentation
  • Coverage
  • 100%
    17 out of 17 items documented0 out of 16 items with examples
  • Size
  • Source code size: 31.94 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.26 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • orlp/int-cast
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • orlp

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 for more information on usage.

License

Licensed under either of

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.