[][src]Trait fixed::sealed::Int

pub trait Int: SealedInt {
    fn from_fixed<F>(val: F) -> Self
    where
        F: Fixed
, { ... }
fn to_fixed<F>(self) -> F
    where
        F: Fixed
, { ... }
fn checked_from_fixed<F>(val: F) -> Option<Self>
    where
        F: Fixed
, { ... }
fn checked_to_fixed<F>(self) -> Option<F>
    where
        F: Fixed
, { ... }
fn saturating_from_fixed<F>(val: F) -> Self
    where
        F: Fixed
, { ... }
fn saturating_to_fixed<F>(self) -> F
    where
        F: Fixed
, { ... }
fn wrapping_from_fixed<F>(val: F) -> Self
    where
        F: Fixed
, { ... }
fn wrapping_to_fixed<F>(self) -> F
    where
        F: Fixed
, { ... }
fn overflowing_from_fixed<F>(val: F) -> (Self, bool)
    where
        F: Fixed
, { ... }
fn overflowing_to_fixed<F>(self) -> (F, bool)
    where
        F: Fixed
, { ... } }

This trait is implemented for all the primitive integer types.

This trait is sealed and cannot be implemented for more types; it is implemented for i8, i16, i32, i64, i128, u8, u16, u32, u64, and u128.

Provided methods

fn from_fixed<F>(val: F) -> Self where
    F: Fixed

Converts from a fixed-point number.

Any fractional bits are truncated.

Panics

In debug mode, panics if the value does not fit. In release mode the value is wrapped, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_from_fixed instead.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedI16<fixed::frac::U8>;
let fix = Fix::from_bits(-3 << 8 | 5);
assert_eq!(i32::from_fixed(fix), -3);

fn to_fixed<F>(self) -> F where
    F: Fixed

Converts to a fixed-point number.

Panics

In debug mode, panics if the value does not fit. In release mode the value is wrapped, but it is not considered a breaking change if in the future it panics; if wrapping is required use wrapping_to_fixed instead.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedI16<fixed::frac::U8>;
let fix: Fix = 3.to_fixed();
assert_eq!(fix, Fix::from_bits(3 << 8));

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed

Converts from a fixed-point number if it fits, otherwise returns None.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedI16<fixed::frac::U8>;
let fix = Fix::from_bits(-3 << 8 | 5);
assert_eq!(i32::checked_from_fixed(fix), Some(-3));
assert!(u32::checked_from_fixed(fix).is_none());

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed

Converts to a fixed-point number if it fits, otherwise returns None.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedI16<fixed::frac::U8>;
assert_eq!(3.checked_to_fixed::<Fix>(), Some(Fix::from_bits(3 << 8)));
assert!(i32::max_value().checked_to_fixed::<Fix>().is_none());

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed

Converts from a fixed-point number, saturating if it does not fit.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedI16<fixed::frac::U8>;
let fix = Fix::from_bits(-3 << 8 | 5);
assert_eq!(i32::saturating_from_fixed(fix), -3);
assert_eq!(u32::saturating_from_fixed(fix), 0);

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed

Converts to a fixed-point number, saturating if it does not fit.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedU16<fixed::frac::U8>;
assert_eq!(3i64.saturating_to_fixed::<Fix>(), Fix::from_bits(3 << 8));
assert_eq!((-1i8).saturating_to_fixed::<Fix>(), Fix::min_value());

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed

Converts from a fixed-point number, wrapping if it does not fit.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedI16<fixed::frac::U8>;
let fix = Fix::from_bits(-3 << 8 | 5);
assert_eq!(i32::wrapping_from_fixed(fix), -3);
assert_eq!(u32::wrapping_from_fixed(fix), 3u32.wrapping_neg());

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed

Converts to a fixed-point number, wrapping if it does not fit.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedU16<fixed::frac::U8>;
assert_eq!(3i64.wrapping_to_fixed::<Fix>(), Fix::from_bits(3 << 8));
assert_eq!((-1i8).wrapping_to_fixed::<Fix>(), Fix::from_bits(0xff00));

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed

Converts from a fixed-point number.

Returns a tuple of the integer and a bool indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedI16<fixed::frac::U8>;
let fix = Fix::from_bits(-3 << 8 | 5);
assert_eq!(i32::overflowing_from_fixed(fix), (-3, false));
assert_eq!(u32::overflowing_from_fixed(fix), (3u32.wrapping_neg(), true));

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed

Converts to a fixed-point number.

Returns a tuple of the fixed-point number and a bool indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

Examples

use fixed::sealed::Int;
type Fix = fixed::FixedU16<fixed::frac::U8>;
assert_eq!(3i64.overflowing_to_fixed::<Fix>(), (Fix::from_bits(3 << 8), false));
assert_eq!((-1i8).overflowing_to_fixed::<Fix>(), (Fix::from_bits(0xff00), true));
Loading content...

Implementors

impl Int for i8[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

impl Int for i16[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

impl Int for i32[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

impl Int for i64[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

impl Int for i128[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

impl Int for u8[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

impl Int for u16[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

impl Int for u32[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

impl Int for u64[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

impl Int for u128[src]

fn from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn checked_from_fixed<F>(val: F) -> Option<Self> where
    F: Fixed
[src]

fn checked_to_fixed<F>(self) -> Option<F> where
    F: Fixed
[src]

fn saturating_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn saturating_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn wrapping_from_fixed<F>(val: F) -> Self where
    F: Fixed
[src]

fn wrapping_to_fixed<F>(self) -> F where
    F: Fixed
[src]

fn overflowing_from_fixed<F>(val: F) -> (Self, bool) where
    F: Fixed
[src]

fn overflowing_to_fixed<F>(self) -> (F, bool) where
    F: Fixed
[src]

Loading content...