Trait fixed::traits::FixedEquiv

source ·
pub trait FixedEquiv {
    type Equiv: Fixed;

    // Required methods
    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.

#![feature(generic_const_exprs)]

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.

#![feature(generic_const_exprs)]

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);

Required Associated Types§

source

type Equiv: Fixed

The equivalent fixed-point type.

Required Methods§

source

fn to_fixed_equiv(self) -> Self::Equiv

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

source

fn as_fixed_equiv(&self) -> &Self::Equiv

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

source

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

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

source

fn from_fixed_equiv(f: Self::Equiv) -> Self

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

source

fn ref_from_fixed_equiv(f: &Self::Equiv) -> &Self

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

source

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

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

Implementations on Foreign Types§

source§

impl FixedEquiv for i8

§

type Equiv = FixedI8<0>

source§

fn to_fixed_equiv(self) -> FixedI8<{ _ }>

source§

fn as_fixed_equiv(&self) -> &FixedI8<{ _ }>

source§

fn as_fixed_equiv_mut(&mut self) -> &mut FixedI8<{ _ }>

source§

fn from_fixed_equiv(f: FixedI8<{ _ }>) -> i8

source§

fn ref_from_fixed_equiv(f: &FixedI8<{ _ }>) -> &i8

source§

fn mut_from_fixed_equiv(f: &mut FixedI8<{ _ }>) -> &mut i8

source§

impl FixedEquiv for i32

§

type Equiv = FixedI32<0>

source§

fn to_fixed_equiv(self) -> FixedI32<{ _ }>

source§

fn as_fixed_equiv(&self) -> &FixedI32<{ _ }>

source§

fn as_fixed_equiv_mut(&mut self) -> &mut FixedI32<{ _ }>

source§

fn from_fixed_equiv(f: FixedI32<{ _ }>) -> i32

source§

fn ref_from_fixed_equiv(f: &FixedI32<{ _ }>) -> &i32

source§

fn mut_from_fixed_equiv(f: &mut FixedI32<{ _ }>) -> &mut i32

source§

impl FixedEquiv for u8

§

type Equiv = FixedU8<0>

source§

fn to_fixed_equiv(self) -> FixedU8<{ _ }>

source§

fn as_fixed_equiv(&self) -> &FixedU8<{ _ }>

source§

fn as_fixed_equiv_mut(&mut self) -> &mut FixedU8<{ _ }>

source§

fn from_fixed_equiv(f: FixedU8<{ _ }>) -> u8

source§

fn ref_from_fixed_equiv(f: &FixedU8<{ _ }>) -> &u8

source§

fn mut_from_fixed_equiv(f: &mut FixedU8<{ _ }>) -> &mut u8

source§

impl FixedEquiv for i16

§

type Equiv = FixedI16<0>

source§

fn to_fixed_equiv(self) -> FixedI16<{ _ }>

source§

fn as_fixed_equiv(&self) -> &FixedI16<{ _ }>

source§

fn as_fixed_equiv_mut(&mut self) -> &mut FixedI16<{ _ }>

source§

fn from_fixed_equiv(f: FixedI16<{ _ }>) -> i16

source§

fn ref_from_fixed_equiv(f: &FixedI16<{ _ }>) -> &i16

source§

fn mut_from_fixed_equiv(f: &mut FixedI16<{ _ }>) -> &mut i16

source§

impl FixedEquiv for u128

source§

impl FixedEquiv for u32

§

type Equiv = FixedU32<0>

source§

fn to_fixed_equiv(self) -> FixedU32<{ _ }>

source§

fn as_fixed_equiv(&self) -> &FixedU32<{ _ }>

source§

fn as_fixed_equiv_mut(&mut self) -> &mut FixedU32<{ _ }>

source§

fn from_fixed_equiv(f: FixedU32<{ _ }>) -> u32

source§

fn ref_from_fixed_equiv(f: &FixedU32<{ _ }>) -> &u32

source§

fn mut_from_fixed_equiv(f: &mut FixedU32<{ _ }>) -> &mut u32

source§

impl FixedEquiv for u16

§

type Equiv = FixedU16<0>

source§

fn to_fixed_equiv(self) -> FixedU16<{ _ }>

source§

fn as_fixed_equiv(&self) -> &FixedU16<{ _ }>

source§

fn as_fixed_equiv_mut(&mut self) -> &mut FixedU16<{ _ }>

source§

fn from_fixed_equiv(f: FixedU16<{ _ }>) -> u16

source§

fn ref_from_fixed_equiv(f: &FixedU16<{ _ }>) -> &u16

source§

fn mut_from_fixed_equiv(f: &mut FixedU16<{ _ }>) -> &mut u16

source§

impl FixedEquiv for i128

source§

impl FixedEquiv for i64

§

type Equiv = FixedI64<0>

source§

fn to_fixed_equiv(self) -> FixedI64<{ _ }>

source§

fn as_fixed_equiv(&self) -> &FixedI64<{ _ }>

source§

fn as_fixed_equiv_mut(&mut self) -> &mut FixedI64<{ _ }>

source§

fn from_fixed_equiv(f: FixedI64<{ _ }>) -> i64

source§

fn ref_from_fixed_equiv(f: &FixedI64<{ _ }>) -> &i64

source§

fn mut_from_fixed_equiv(f: &mut FixedI64<{ _ }>) -> &mut i64

source§

impl FixedEquiv for u64

§

type Equiv = FixedU64<0>

source§

fn to_fixed_equiv(self) -> FixedU64<{ _ }>

source§

fn as_fixed_equiv(&self) -> &FixedU64<{ _ }>

source§

fn as_fixed_equiv_mut(&mut self) -> &mut FixedU64<{ _ }>

source§

fn from_fixed_equiv(f: FixedU64<{ _ }>) -> u64

source§

fn ref_from_fixed_equiv(f: &FixedU64<{ _ }>) -> &u64

source§

fn mut_from_fixed_equiv(f: &mut FixedU64<{ _ }>) -> &mut u64

Implementors§