Skip to main content

Approx

Struct Approx 

Source
pub struct Approx;
Expand description

Approximate conversion

This rounding mode allows an implementation-defined rounding mode. The result must be close to the input value (see below).

Example: 2.1_f32 may convert to 2_i32 or to 3_i32 (either implementation is valid so long as the behaviour is well-defined).

§Limits of approximation

(This section applies to all Rounding modes provided by easy-cast except for Exact.)

The output value of a successful conversion must be close to the input value. More precisely, the distance between the input and output values should be less than the distance between the two closest representable values in the target type. For example, 1.9_f32 may be approximated to 1_i32 or 2_i32 since mathematically 1.9 lies between 1 and 2. As another example, 1_f64 + (f32::EPSILON as f64) / 2.0 may be approximated to 1_f32 or 1_f32 + f32::EPSILON.

Infinity “values” like f32::INFINITY are a bit special; essentially we allow any input of the appropriate sign to approximate to “infinity” where the input may not approximate to another value. For example, the above rules may be used to calculate the maximum u128 value which is allowed to approximate to f32::MAX (0xFFFFFF7F_FFFFFFFF_FFFFFFFF_FFFFFFFF); the value above this should thus approximate to f32::INFINITY.

Trait Implementations§

Source§

impl Clone for Approx

Source§

fn clone(&self) -> Approx

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S, T: ConvExact<S>> ConvTo<S, Approx> for T

Source§

type Error = <T as ConvExact<S>>::Error

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, s: S) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, s: S) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for i8

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for i16

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for i32

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for i64

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for i128

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for isize

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for u8

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for u16

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for u32

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for u64

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for usize

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f32, Approx> for u128

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f32) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for f32

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<f32, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> f32

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for i8

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for i16

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for i32

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for i64

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for i128

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for isize

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for u8

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for u16

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for u32

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for u64

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for u128

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<f64, Approx> for usize

Source§

type Error = RangeError

Conversion error type Read more
Source§

fn try_conv_to(_: Approx, x: f64) -> Result<Self, Self::Error>

Try converting from S to Self, rounding according to mode
Source§

fn conv_to(_: Approx, x: f64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

impl ConvTo<i32, Approx> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: i32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: i32) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<i64, Approx> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: i64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: i64) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<i64, Approx> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: i64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: i64) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<i128, Approx> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: i128) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: i128) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<i128, Approx> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: i128) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: i128) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<isize, Approx> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: isize) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: isize) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<isize, Approx> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: isize) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: isize) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u32, Approx> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: u32) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: u32) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u64, Approx> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: u64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: u64) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u64, Approx> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: u64) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: u64) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u128, Approx> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: u128) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: u128) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<u128, Approx> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: u128) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: u128) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<usize, Approx> for f32

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: usize) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: usize) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl ConvTo<usize, Approx> for f64

Source§

type Error = Infallible

Conversion error type Read more
Source§

fn conv_to(_: Approx, x: usize) -> Self

Convert from S to Self, rounding according to mode Read more
Source§

fn try_conv_to(_: Approx, x: usize) -> Result<Self, Infallible>

Try converting from S to Self, rounding according to mode
Source§

impl Copy for Approx

Source§

impl Debug for Approx

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Approx

Source§

fn default() -> Approx

Returns the “default value” for a type. Read more
Source§

impl Rounding for Approx

Source§

type MaximumError = RangeError

Maximum error type

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<S, T> Cast<T> for S
where T: Conv<S>,

Source§

type Error = <T as Conv<S>>::Error

Conversion error type Read more
Source§

fn cast(self) -> T

Cast from Self to T Read more
Source§

fn try_cast(self) -> Result<T, <S as Cast<T>>::Error>

Try converting from Self to T
Source§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

Source§

type Error = <T as ConvApprox<S>>::Error

Conversion error type Read more
Source§

fn try_cast_approx(self) -> Result<T, <S as CastApprox<T>>::Error>

Try approximate conversion from Self to T
Source§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
Source§

impl<R, S, T> CastTo<T, R> for S
where R: Rounding, T: ConvTo<S, R>,

Source§

type Error = <T as ConvTo<S, R>>::Error

Conversion error type Read more
Source§

fn try_cast_to(self, mode: R) -> Result<T, <S as CastTo<T, R>>::Error>

Try converting from Self to T, rounding according to mode
Source§

fn cast_to(self, mode: R) -> T

Convert from Self to T, rounding according to mode Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.