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
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.
Implementations on Foreign Types
impl FixedEquiv for i8
[src]
impl FixedEquiv for i8
[src]type Equiv = FixedI8<U0>
fn to_fixed_equiv(self) -> FixedI8<U0>
[src]
fn as_fixed_equiv(&self) -> &FixedI8<U0>
[src]
fn as_fixed_equiv_mut(&mut self) -> &mut FixedI8<U0>
[src]
fn from_fixed_equiv(f: FixedI8<U0>) -> i8
[src]
fn ref_from_fixed_equiv(f: &FixedI8<U0>) -> &i8
[src]
fn mut_from_fixed_equiv(f: &mut FixedI8<U0>) -> &mut i8
[src]
impl FixedEquiv for i16
[src]
impl FixedEquiv for i16
[src]type Equiv = FixedI16<U0>
fn to_fixed_equiv(self) -> FixedI16<U0>
[src]
fn as_fixed_equiv(&self) -> &FixedI16<U0>
[src]
fn as_fixed_equiv_mut(&mut self) -> &mut FixedI16<U0>
[src]
fn from_fixed_equiv(f: FixedI16<U0>) -> i16
[src]
fn ref_from_fixed_equiv(f: &FixedI16<U0>) -> &i16
[src]
fn mut_from_fixed_equiv(f: &mut FixedI16<U0>) -> &mut i16
[src]
impl FixedEquiv for i32
[src]
impl FixedEquiv for i32
[src]type Equiv = FixedI32<U0>
fn to_fixed_equiv(self) -> FixedI32<U0>
[src]
fn as_fixed_equiv(&self) -> &FixedI32<U0>
[src]
fn as_fixed_equiv_mut(&mut self) -> &mut FixedI32<U0>
[src]
fn from_fixed_equiv(f: FixedI32<U0>) -> i32
[src]
fn ref_from_fixed_equiv(f: &FixedI32<U0>) -> &i32
[src]
fn mut_from_fixed_equiv(f: &mut FixedI32<U0>) -> &mut i32
[src]
impl FixedEquiv for i64
[src]
impl FixedEquiv for i64
[src]type Equiv = FixedI64<U0>
fn to_fixed_equiv(self) -> FixedI64<U0>
[src]
fn as_fixed_equiv(&self) -> &FixedI64<U0>
[src]
fn as_fixed_equiv_mut(&mut self) -> &mut FixedI64<U0>
[src]
fn from_fixed_equiv(f: FixedI64<U0>) -> i64
[src]
fn ref_from_fixed_equiv(f: &FixedI64<U0>) -> &i64
[src]
fn mut_from_fixed_equiv(f: &mut FixedI64<U0>) -> &mut i64
[src]
impl FixedEquiv for i128
[src]
impl FixedEquiv for i128
[src]type Equiv = FixedI128<U0>
fn to_fixed_equiv(self) -> FixedI128<U0>
[src]
fn as_fixed_equiv(&self) -> &FixedI128<U0>
[src]
fn as_fixed_equiv_mut(&mut self) -> &mut FixedI128<U0>
[src]
fn from_fixed_equiv(f: FixedI128<U0>) -> i128
[src]
fn ref_from_fixed_equiv(f: &FixedI128<U0>) -> &i128
[src]
fn mut_from_fixed_equiv(f: &mut FixedI128<U0>) -> &mut i128
[src]
impl FixedEquiv for u8
[src]
impl FixedEquiv for u8
[src]type Equiv = FixedU8<U0>
fn to_fixed_equiv(self) -> FixedU8<U0>
[src]
fn as_fixed_equiv(&self) -> &FixedU8<U0>
[src]
fn as_fixed_equiv_mut(&mut self) -> &mut FixedU8<U0>
[src]
fn from_fixed_equiv(f: FixedU8<U0>) -> u8
[src]
fn ref_from_fixed_equiv(f: &FixedU8<U0>) -> &u8
[src]
fn mut_from_fixed_equiv(f: &mut FixedU8<U0>) -> &mut u8
[src]
impl FixedEquiv for u16
[src]
impl FixedEquiv for u16
[src]type Equiv = FixedU16<U0>
fn to_fixed_equiv(self) -> FixedU16<U0>
[src]
fn as_fixed_equiv(&self) -> &FixedU16<U0>
[src]
fn as_fixed_equiv_mut(&mut self) -> &mut FixedU16<U0>
[src]
fn from_fixed_equiv(f: FixedU16<U0>) -> u16
[src]
fn ref_from_fixed_equiv(f: &FixedU16<U0>) -> &u16
[src]
fn mut_from_fixed_equiv(f: &mut FixedU16<U0>) -> &mut u16
[src]
impl FixedEquiv for u32
[src]
impl FixedEquiv for u32
[src]type Equiv = FixedU32<U0>
fn to_fixed_equiv(self) -> FixedU32<U0>
[src]
fn as_fixed_equiv(&self) -> &FixedU32<U0>
[src]
fn as_fixed_equiv_mut(&mut self) -> &mut FixedU32<U0>
[src]
fn from_fixed_equiv(f: FixedU32<U0>) -> u32
[src]
fn ref_from_fixed_equiv(f: &FixedU32<U0>) -> &u32
[src]
fn mut_from_fixed_equiv(f: &mut FixedU32<U0>) -> &mut u32
[src]
impl FixedEquiv for u64
[src]
impl FixedEquiv for u64
[src]type Equiv = FixedU64<U0>
fn to_fixed_equiv(self) -> FixedU64<U0>
[src]
fn as_fixed_equiv(&self) -> &FixedU64<U0>
[src]
fn as_fixed_equiv_mut(&mut self) -> &mut FixedU64<U0>
[src]
fn from_fixed_equiv(f: FixedU64<U0>) -> u64
[src]
fn ref_from_fixed_equiv(f: &FixedU64<U0>) -> &u64
[src]
fn mut_from_fixed_equiv(f: &mut FixedU64<U0>) -> &mut u64
[src]
impl FixedEquiv for u128
[src]
impl FixedEquiv for u128
[src]