Skip to content

orlp/int-cast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

This Rust crate provides convenient casts between primitive integers.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages