Skip to main content

ConvExact

Trait ConvExact 

Source
pub trait ConvExact<S>: Sized {
    type Error: Into<RangeError> + Into<Error> + Error;

    // Required method
    fn try_conv_exact(s: S) -> Result<Self, Self::Error>;

    // Provided method
    fn conv_exact(s: S) -> Self { ... }
}
Expand description

Generic “from” conversion trait for exact conversions

This trait is provided as an implementation aid only, hence there is no CastExact (in most cases you can just use Cast).

§Implementing exact conversions

Implement conversions which cannot lose precision using this trait. Implementations of ConvTo<S, R> are implied for all R: Rounding modes provided by this crate (see § Implied implementations).

§Example

use easy_cast::ConvExact;
use std::convert::Infallible;

struct MyBigInt { /* details */ }

// Support conversion from i32:
impl ConvExact<i32> for MyBigInt {
    type Error = Infallible;

    fn try_conv_exact(i: i32) -> Result<Self, Infallible> {
        Ok(todo!())
    }

    // optionally also impl fn conv_exact
}

Note that in practice you’ll probably want to support conversion from many integer types using macro_rules!. Or you could “cheat” with a generic impl<S: Into<i128>> ConvExact<S> for MyBigInt { ... }.

Required Associated Types§

Source

type Error: Into<RangeError> + Into<Error> + Error

Conversion error type

This should be either Infallible or RangeError.

Required Methods§

Source

fn try_conv_exact(s: S) -> Result<Self, Self::Error>

Try converting from S to Self

Provided Methods§

Source

fn conv_exact(s: S) -> Self

Convert from S to Self

Use this method only when success is expected. On error, this method may panic or may exhibit § Fallback behaviour.

§Implementing

Implementing this method directly (with fallback behaviour) is optional. In debug builds, this method must panic on error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ConvExact<NonZero<i8>> for NonZero<i8>

Source§

impl ConvExact<NonZero<i8>> for NonZero<i16>

Source§

impl ConvExact<NonZero<i8>> for NonZero<i32>

Source§

impl ConvExact<NonZero<i8>> for NonZero<i64>

Source§

impl ConvExact<NonZero<i8>> for NonZero<i128>

Source§

impl ConvExact<NonZero<i8>> for NonZero<isize>

Source§

impl ConvExact<NonZero<i8>> for NonZero<u8>

Source§

impl ConvExact<NonZero<i8>> for NonZero<u16>

Source§

impl ConvExact<NonZero<i8>> for NonZero<u32>

Source§

impl ConvExact<NonZero<i8>> for NonZero<u64>

Source§

impl ConvExact<NonZero<i8>> for NonZero<u128>

Source§

impl ConvExact<NonZero<i8>> for NonZero<usize>

Source§

impl ConvExact<NonZero<i16>> for NonZero<i8>

Source§

impl ConvExact<NonZero<i16>> for NonZero<i16>

Source§

impl ConvExact<NonZero<i16>> for NonZero<i32>

Source§

impl ConvExact<NonZero<i16>> for NonZero<i64>

Source§

impl ConvExact<NonZero<i16>> for NonZero<i128>

Source§

impl ConvExact<NonZero<i16>> for NonZero<isize>

Source§

impl ConvExact<NonZero<i16>> for NonZero<u8>

Source§

impl ConvExact<NonZero<i16>> for NonZero<u16>

Source§

impl ConvExact<NonZero<i16>> for NonZero<u32>

Source§

impl ConvExact<NonZero<i16>> for NonZero<u64>

Source§

impl ConvExact<NonZero<i16>> for NonZero<u128>

Source§

impl ConvExact<NonZero<i16>> for NonZero<usize>

Source§

impl ConvExact<NonZero<i32>> for NonZero<i8>

Source§

impl ConvExact<NonZero<i32>> for NonZero<i16>

Source§

impl ConvExact<NonZero<i32>> for NonZero<i32>

Source§

impl ConvExact<NonZero<i32>> for NonZero<i64>

Source§

impl ConvExact<NonZero<i32>> for NonZero<i128>

Source§

impl ConvExact<NonZero<i32>> for NonZero<isize>

Source§

impl ConvExact<NonZero<i32>> for NonZero<u8>

Source§

impl ConvExact<NonZero<i32>> for NonZero<u16>

Source§

impl ConvExact<NonZero<i32>> for NonZero<u32>

Source§

impl ConvExact<NonZero<i32>> for NonZero<u64>

Source§

impl ConvExact<NonZero<i32>> for NonZero<u128>

Source§

impl ConvExact<NonZero<i32>> for NonZero<usize>

Source§

impl ConvExact<NonZero<i64>> for NonZero<i8>

Source§

impl ConvExact<NonZero<i64>> for NonZero<i16>

Source§

impl ConvExact<NonZero<i64>> for NonZero<i32>

Source§

impl ConvExact<NonZero<i64>> for NonZero<i64>

Source§

impl ConvExact<NonZero<i64>> for NonZero<i128>

Source§

impl ConvExact<NonZero<i64>> for NonZero<isize>

Source§

impl ConvExact<NonZero<i64>> for NonZero<u8>

Source§

impl ConvExact<NonZero<i64>> for NonZero<u16>

Source§

impl ConvExact<NonZero<i64>> for NonZero<u32>

Source§

impl ConvExact<NonZero<i64>> for NonZero<u64>

Source§

impl ConvExact<NonZero<i64>> for NonZero<u128>

Source§

impl ConvExact<NonZero<i64>> for NonZero<usize>

Source§

impl ConvExact<NonZero<i128>> for NonZero<i8>

Source§

impl ConvExact<NonZero<i128>> for NonZero<i16>

Source§

impl ConvExact<NonZero<i128>> for NonZero<i32>

Source§

impl ConvExact<NonZero<i128>> for NonZero<i64>

Source§

impl ConvExact<NonZero<i128>> for NonZero<i128>

Source§

impl ConvExact<NonZero<i128>> for NonZero<isize>

Source§

impl ConvExact<NonZero<i128>> for NonZero<u8>

Source§

impl ConvExact<NonZero<i128>> for NonZero<u16>

Source§

impl ConvExact<NonZero<i128>> for NonZero<u32>

Source§

impl ConvExact<NonZero<i128>> for NonZero<u64>

Source§

impl ConvExact<NonZero<i128>> for NonZero<u128>

Source§

impl ConvExact<NonZero<i128>> for NonZero<usize>

Source§

impl ConvExact<NonZero<isize>> for NonZero<i8>

Source§

impl ConvExact<NonZero<isize>> for NonZero<i16>

Source§

impl ConvExact<NonZero<isize>> for NonZero<i32>

Source§

impl ConvExact<NonZero<isize>> for NonZero<i64>

Source§

impl ConvExact<NonZero<isize>> for NonZero<i128>

Source§

impl ConvExact<NonZero<isize>> for NonZero<isize>

Source§

impl ConvExact<NonZero<isize>> for NonZero<u8>

Source§

impl ConvExact<NonZero<isize>> for NonZero<u16>

Source§

impl ConvExact<NonZero<isize>> for NonZero<u32>

Source§

impl ConvExact<NonZero<isize>> for NonZero<u64>

Source§

impl ConvExact<NonZero<isize>> for NonZero<u128>

Source§

impl ConvExact<NonZero<isize>> for NonZero<usize>

Source§

impl ConvExact<NonZero<u8>> for NonZero<i8>

Source§

impl ConvExact<NonZero<u8>> for NonZero<i16>

Source§

impl ConvExact<NonZero<u8>> for NonZero<i32>

Source§

impl ConvExact<NonZero<u8>> for NonZero<i64>

Source§

impl ConvExact<NonZero<u8>> for NonZero<i128>

Source§

impl ConvExact<NonZero<u8>> for NonZero<isize>

Source§

impl ConvExact<NonZero<u8>> for NonZero<u8>

Source§

impl ConvExact<NonZero<u8>> for NonZero<u16>

Source§

impl ConvExact<NonZero<u8>> for NonZero<u32>

Source§

impl ConvExact<NonZero<u8>> for NonZero<u64>

Source§

impl ConvExact<NonZero<u8>> for NonZero<u128>

Source§

impl ConvExact<NonZero<u8>> for NonZero<usize>

Source§

impl ConvExact<NonZero<u16>> for NonZero<i8>

Source§

impl ConvExact<NonZero<u16>> for NonZero<i16>

Source§

impl ConvExact<NonZero<u16>> for NonZero<i32>

Source§

impl ConvExact<NonZero<u16>> for NonZero<i64>

Source§

impl ConvExact<NonZero<u16>> for NonZero<i128>

Source§

impl ConvExact<NonZero<u16>> for NonZero<isize>

Source§

impl ConvExact<NonZero<u16>> for NonZero<u8>

Source§

impl ConvExact<NonZero<u16>> for NonZero<u16>

Source§

impl ConvExact<NonZero<u16>> for NonZero<u32>

Source§

impl ConvExact<NonZero<u16>> for NonZero<u64>

Source§

impl ConvExact<NonZero<u16>> for NonZero<u128>

Source§

impl ConvExact<NonZero<u16>> for NonZero<usize>

Source§

impl ConvExact<NonZero<u32>> for NonZero<i8>

Source§

impl ConvExact<NonZero<u32>> for NonZero<i16>

Source§

impl ConvExact<NonZero<u32>> for NonZero<i32>

Source§

impl ConvExact<NonZero<u32>> for NonZero<i64>

Source§

impl ConvExact<NonZero<u32>> for NonZero<i128>

Source§

impl ConvExact<NonZero<u32>> for NonZero<isize>

Source§

impl ConvExact<NonZero<u32>> for NonZero<u8>

Source§

impl ConvExact<NonZero<u32>> for NonZero<u16>

Source§

impl ConvExact<NonZero<u32>> for NonZero<u32>

Source§

impl ConvExact<NonZero<u32>> for NonZero<u64>

Source§

impl ConvExact<NonZero<u32>> for NonZero<u128>

Source§

impl ConvExact<NonZero<u32>> for NonZero<usize>

Source§

impl ConvExact<NonZero<u64>> for NonZero<i8>

Source§

impl ConvExact<NonZero<u64>> for NonZero<i16>

Source§

impl ConvExact<NonZero<u64>> for NonZero<i32>

Source§

impl ConvExact<NonZero<u64>> for NonZero<i64>

Source§

impl ConvExact<NonZero<u64>> for NonZero<i128>

Source§

impl ConvExact<NonZero<u64>> for NonZero<isize>

Source§

impl ConvExact<NonZero<u64>> for NonZero<u8>

Source§

impl ConvExact<NonZero<u64>> for NonZero<u16>

Source§

impl ConvExact<NonZero<u64>> for NonZero<u32>

Source§

impl ConvExact<NonZero<u64>> for NonZero<u64>

Source§

impl ConvExact<NonZero<u64>> for NonZero<u128>

Source§

impl ConvExact<NonZero<u64>> for NonZero<usize>

Source§

impl ConvExact<NonZero<u128>> for NonZero<i8>

Source§

impl ConvExact<NonZero<u128>> for NonZero<i16>

Source§

impl ConvExact<NonZero<u128>> for NonZero<i32>

Source§

impl ConvExact<NonZero<u128>> for NonZero<i64>

Source§

impl ConvExact<NonZero<u128>> for NonZero<i128>

Source§

impl ConvExact<NonZero<u128>> for NonZero<isize>

Source§

impl ConvExact<NonZero<u128>> for NonZero<u8>

Source§

impl ConvExact<NonZero<u128>> for NonZero<u16>

Source§

impl ConvExact<NonZero<u128>> for NonZero<u32>

Source§

impl ConvExact<NonZero<u128>> for NonZero<u64>

Source§

impl ConvExact<NonZero<u128>> for NonZero<u128>

Source§

impl ConvExact<NonZero<u128>> for NonZero<usize>

Source§

impl ConvExact<NonZero<usize>> for NonZero<i8>

Source§

impl ConvExact<NonZero<usize>> for NonZero<i16>

Source§

impl ConvExact<NonZero<usize>> for NonZero<i32>

Source§

impl ConvExact<NonZero<usize>> for NonZero<i64>

Source§

impl ConvExact<NonZero<usize>> for NonZero<i128>

Source§

impl ConvExact<NonZero<usize>> for NonZero<isize>

Source§

impl ConvExact<NonZero<usize>> for NonZero<u8>

Source§

impl ConvExact<NonZero<usize>> for NonZero<u16>

Source§

impl ConvExact<NonZero<usize>> for NonZero<u32>

Source§

impl ConvExact<NonZero<usize>> for NonZero<u64>

Source§

impl ConvExact<NonZero<usize>> for NonZero<u128>

Source§

impl ConvExact<NonZero<usize>> for NonZero<usize>

Source§

impl ConvExact<f32> for f32

Source§

impl ConvExact<f32> for f64

Source§

impl ConvExact<f64> for f64

Source§

impl ConvExact<i8> for f32

Source§

impl ConvExact<i8> for f64

Source§

impl ConvExact<i8> for i8

Source§

impl ConvExact<i8> for i16

Source§

impl ConvExact<i8> for i32

Source§

impl ConvExact<i8> for i64

Source§

impl ConvExact<i8> for i128

Source§

impl ConvExact<i8> for isize

Source§

impl ConvExact<i8> for u8

Source§

impl ConvExact<i8> for u16

Source§

impl ConvExact<i8> for u32

Source§

impl ConvExact<i8> for u64

Source§

impl ConvExact<i8> for u128

Source§

impl ConvExact<i8> for usize

Source§

impl ConvExact<i16> for f32

Source§

impl ConvExact<i16> for f64

Source§

impl ConvExact<i16> for i8

Source§

impl ConvExact<i16> for i16

Source§

impl ConvExact<i16> for i32

Source§

impl ConvExact<i16> for i64

Source§

impl ConvExact<i16> for i128

Source§

impl ConvExact<i16> for isize

Source§

impl ConvExact<i16> for u8

Source§

impl ConvExact<i16> for u16

Source§

impl ConvExact<i16> for u32

Source§

impl ConvExact<i16> for u64

Source§

impl ConvExact<i16> for u128

Source§

impl ConvExact<i16> for usize

Source§

impl ConvExact<i32> for f64

Source§

impl ConvExact<i32> for i8

Source§

impl ConvExact<i32> for i16

Source§

impl ConvExact<i32> for i32

Source§

impl ConvExact<i32> for i64

Source§

impl ConvExact<i32> for i128

Source§

impl ConvExact<i32> for isize

Source§

impl ConvExact<i32> for u8

Source§

impl ConvExact<i32> for u16

Source§

impl ConvExact<i32> for u32

Source§

impl ConvExact<i32> for u64

Source§

impl ConvExact<i32> for u128

Source§

impl ConvExact<i32> for usize

Source§

impl ConvExact<i64> for i8

Source§

impl ConvExact<i64> for i16

Source§

impl ConvExact<i64> for i32

Source§

impl ConvExact<i64> for i64

Source§

impl ConvExact<i64> for i128

Source§

impl ConvExact<i64> for isize

Source§

impl ConvExact<i64> for u8

Source§

impl ConvExact<i64> for u16

Source§

impl ConvExact<i64> for u32

Source§

impl ConvExact<i64> for u64

Source§

impl ConvExact<i64> for u128

Source§

impl ConvExact<i64> for usize

Source§

impl ConvExact<i128> for i8

Source§

impl ConvExact<i128> for i16

Source§

impl ConvExact<i128> for i32

Source§

impl ConvExact<i128> for i64

Source§

impl ConvExact<i128> for i128

Source§

impl ConvExact<i128> for isize

Source§

impl ConvExact<i128> for u8

Source§

impl ConvExact<i128> for u16

Source§

impl ConvExact<i128> for u32

Source§

impl ConvExact<i128> for u64

Source§

impl ConvExact<i128> for u128

Source§

impl ConvExact<i128> for usize

Source§

impl ConvExact<isize> for i8

Source§

impl ConvExact<isize> for i16

Source§

impl ConvExact<isize> for i32

Source§

impl ConvExact<isize> for i64

Source§

impl ConvExact<isize> for i128

Source§

impl ConvExact<isize> for isize

Source§

impl ConvExact<isize> for u8

Source§

impl ConvExact<isize> for u16

Source§

impl ConvExact<isize> for u32

Source§

impl ConvExact<isize> for u64

Source§

impl ConvExact<isize> for u128

Source§

impl ConvExact<isize> for usize

Source§

impl ConvExact<u8> for f32

Source§

impl ConvExact<u8> for f64

Source§

impl ConvExact<u8> for i8

Source§

impl ConvExact<u8> for i16

Source§

impl ConvExact<u8> for i32

Source§

impl ConvExact<u8> for i64

Source§

impl ConvExact<u8> for i128

Source§

impl ConvExact<u8> for isize

Source§

impl ConvExact<u8> for u8

Source§

impl ConvExact<u8> for u16

Source§

impl ConvExact<u8> for u32

Source§

impl ConvExact<u8> for u64

Source§

impl ConvExact<u8> for u128

Source§

impl ConvExact<u8> for usize

Source§

impl ConvExact<u16> for f32

Source§

impl ConvExact<u16> for f64

Source§

impl ConvExact<u16> for i8

Source§

impl ConvExact<u16> for i16

Source§

impl ConvExact<u16> for i32

Source§

impl ConvExact<u16> for i64

Source§

impl ConvExact<u16> for i128

Source§

impl ConvExact<u16> for isize

Source§

impl ConvExact<u16> for u8

Source§

impl ConvExact<u16> for u16

Source§

impl ConvExact<u16> for u32

Source§

impl ConvExact<u16> for u64

Source§

impl ConvExact<u16> for u128

Source§

impl ConvExact<u16> for usize

Source§

impl ConvExact<u32> for f64

Source§

impl ConvExact<u32> for i8

Source§

impl ConvExact<u32> for i16

Source§

impl ConvExact<u32> for i32

Source§

impl ConvExact<u32> for i64

Source§

impl ConvExact<u32> for i128

Source§

impl ConvExact<u32> for isize

Source§

impl ConvExact<u32> for u8

Source§

impl ConvExact<u32> for u16

Source§

impl ConvExact<u32> for u32

Source§

impl ConvExact<u32> for u64

Source§

impl ConvExact<u32> for u128

Source§

impl ConvExact<u32> for usize

Source§

impl ConvExact<u64> for i8

Source§

impl ConvExact<u64> for i16

Source§

impl ConvExact<u64> for i32

Source§

impl ConvExact<u64> for i64

Source§

impl ConvExact<u64> for i128

Source§

impl ConvExact<u64> for isize

Source§

impl ConvExact<u64> for u8

Source§

impl ConvExact<u64> for u16

Source§

impl ConvExact<u64> for u32

Source§

impl ConvExact<u64> for u64

Source§

impl ConvExact<u64> for u128

Source§

impl ConvExact<u64> for usize

Source§

impl ConvExact<u128> for i8

Source§

impl ConvExact<u128> for i16

Source§

impl ConvExact<u128> for i32

Source§

impl ConvExact<u128> for i64

Source§

impl ConvExact<u128> for i128

Source§

impl ConvExact<u128> for isize

Source§

impl ConvExact<u128> for u8

Source§

impl ConvExact<u128> for u16

Source§

impl ConvExact<u128> for u32

Source§

impl ConvExact<u128> for u64

Source§

impl ConvExact<u128> for u128

Source§

impl ConvExact<u128> for usize

Source§

impl ConvExact<usize> for i8

Source§

impl ConvExact<usize> for i16

Source§

impl ConvExact<usize> for i32

Source§

impl ConvExact<usize> for i64

Source§

impl ConvExact<usize> for i128

Source§

impl ConvExact<usize> for isize

Source§

impl ConvExact<usize> for u8

Source§

impl ConvExact<usize> for u16

Source§

impl ConvExact<usize> for u32

Source§

impl ConvExact<usize> for u64

Source§

impl ConvExact<usize> for u128

Source§

impl ConvExact<usize> for usize

Implementors§