ConvertInto

Trait ConvertInto 

Source
pub trait ConvertInto<S>
where S: Sample,
{ // Required method fn convert_into(self) -> S; }
Expand description

Sample types that can be converted into another Sample type.

Required Methods§

Source

fn convert_into(self) -> S

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

Implementors§

Source§

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