Trait sampara::sample::conv::ConvertInto[][src]

pub trait ConvertInto<S> where
    S: Sample
{ fn convert_into(self) -> S; }

Sample types that can be converted into another Sample type.

Required methods

fn convert_into(self) -> S[src]

Convert Self into another Sample type. This is analogous to std::convert::Into, but is intended for preserving the same represented amplitude between sample types.

This trait has a blanket implementation for all types that implement ConvertFrom.

use sampara::{Sample, ConvertInto};

fn main() {
    let s: i8 = 0.0f32.convert_into();
    assert_eq!(s, 0);

    let s: u8 = 0.0f32.convert_into();
    assert_eq!(s, 128);

    let s: f32 = 255u8.convert_into();
    assert_eq!(s, 0.9921875);
}
Loading content...

Implementors

impl<T, U> ConvertInto<U> for T where
    T: Sample,
    U: ConvertFrom<T> + Sample
[src]

Loading content...