Trait fixed::traits::FixedEquiv[][src]

pub trait FixedEquiv {
    type Equiv: Fixed;
    fn to_fixed_equiv(self) -> Self::Equiv;
fn as_fixed_equiv(&self) -> &Self::Equiv;
fn as_fixed_equiv_mut(&mut self) -> &mut Self::Equiv;
fn from_fixed_equiv(f: Self::Equiv) -> Self;
fn ref_from_fixed_equiv(f: &Self::Equiv) -> &Self;
fn mut_from_fixed_equiv(f: &mut Self::Equiv) -> &mut Self; }
Expand description

This trait provides a way to convert a number to/from an equivalent fixed-point number.

Implementations are provided for the signed integer primitives i8, i16, i32, i64 and i128, which have equivalent fixed-point types I8F0, I16F0, I32F0, I64F0 and I128F0. Similar implementations are provided for the unsigned integer primitives u8, u16, u32, u64 and u128.

Examples

An i32 can be treated as an I32F0.

use fixed::traits::{Fixed, FixedEquiv};

fn next_up<F: Fixed>(f: &mut F) {
    *f += F::DELTA;
}

let mut i = 12i32;
// next_up is called with &mut i converted to &mut I32F0
next_up(i.as_fixed_equiv_mut());
assert_eq!(i, 13);

Simlarly, an I32F0 can be treated as an i32.

use fixed::{traits::FixedEquiv, types::I32F0};

fn increase_by_5(i: &mut i32) {
    *i += 5;
}

let mut f = I32F0::from_num(12);
// increase_by_5 is called with &mut f converted to &mut i32
increase_by_5(i32::mut_from_fixed_equiv(&mut f));
assert_eq!(f, 17);

Associated Types

type Equiv: Fixed[src]

Expand description

The equivalent fixed-point type.

Loading content...

Required methods

fn to_fixed_equiv(self) -> Self::Equiv[src]

Expand description

Converts an owned value to the equivalent fixed-point type.

fn as_fixed_equiv(&self) -> &Self::Equiv[src]

Expand description

Converts a reference into a reference to the equivalent fixed-point type.

fn as_fixed_equiv_mut(&mut self) -> &mut Self::Equiv[src]

Expand description

Converts a mutable reference into a mutable reference to the equivalent fixed-point type.

fn from_fixed_equiv(f: Self::Equiv) -> Self[src]

Expand description

Converts an owned equivalent fixed-point type to this type.

fn ref_from_fixed_equiv(f: &Self::Equiv) -> &Self[src]

Expand description

Converts a reference to the equivalent fixed-point type into a reference to this type.

fn mut_from_fixed_equiv(f: &mut Self::Equiv) -> &mut Self[src]

Expand description

Converts a mutable reference to the equivalent fixed-point type into a mutable reference to this type.

Loading content...

Implementations on Foreign Types

impl FixedEquiv for i8[src]

impl FixedEquiv for i16[src]

impl FixedEquiv for i32[src]

impl FixedEquiv for i64[src]

impl FixedEquiv for i128[src]

impl FixedEquiv for u8[src]

impl FixedEquiv for u16[src]

impl FixedEquiv for u32[src]

impl FixedEquiv for u64[src]

impl FixedEquiv for u128[src]

Loading content...

Implementors

Loading content...