Skip to main content

Crate int_cast

Crate int_cast 

Source
Expand description

This crate provides convenient casts between primitive integers.

The primary entry point is the extension trait IntCast, which will add casting methods to the primitive integer types. The casts provided are:

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>().

All cast traits are sealed meaning you may not implement them for custom types. This is intended, so that the behavior is predictable.

§Features

If you enable the nonzero feature all traits are extended with implementations for core::num::NonZero types. Note that this requires a nightly compiler and uses the very much unstable core::num::ZeroablePrimitive.

Traits§

BoundedCastFromInt
Conversion between integers, wrapping around or saturating at the target type’s boundaries.
CastFromInt
Infallible conversion between integers.
CheckedCastFromInt
Fallible conversion between integers.
IntCast
Extension trait for casting integers.