Crate easy_cast[][src]

Type conversion, success expected

Use Conv and Cast when:

  • From and Into are not enough
  • it is expected that the value can be represented exactly by the target type
  • you could use as, but want some assurance it’s doing the right thing
  • you are converting numbers (future versions might consider supporting other conversions)

Use ConvFloat and CastFloat when:

  • You are converting from f32 or f64
  • You specifically want the nearest or ceiling or floor, but don’t need detailed control over rounding (e.g. round-to-even)

Assertions

All type conversions which are potentially fallible assert on failure in debug builds. In release builds assertions may be omitted, thus making incorrect conversions possible.

If the always_assert feature flag is set, assertions will be turned on in all builds. Some additional feature flags are available for finer-grained control (see Cargo.toml).

Traits

Cast

Like Into, but for Conv

CastFloat

Like Into, but for ConvFloat

Conv

Like From, but supporting potentially-fallible conversions

ConvFloat

Nearest / floor / ceil conversions from floating point types