Trait AudioFormatNum

pub trait AudioFormatNum {
    const SILENCE: Self;

    // Required method
    fn audio_format() -> AudioFormat;
}
Available on crate feature dep_sdl2 only.
Expand description

A phantom type for retrieving the SDL_AudioFormat of a given generic type. All format types are returned as native-endian.

Required Associated Constants§

const SILENCE: Self

The appropriately typed silence value for the audio format used.

§Examples
// The AudioFormatNum trait has to be imported for the Channel::SILENCE part to work.
use sdl2::audio::{AudioCallback, AudioFormatNum};

struct Silence;

impl AudioCallback for Silence {
    type Channel = u16;

    fn callback(&mut self, out: &mut [u16]) {
        for dst in out.iter_mut() {
            *dst = Self::Channel::SILENCE;
        }
    }
}

Required Methods§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl AudioFormatNum for f32

AUDIO_F32

§

impl AudioFormatNum for i8

AUDIO_S8

§

impl AudioFormatNum for i16

AUDIO_S16

§

impl AudioFormatNum for i32

AUDIO_S32

§

impl AudioFormatNum for u8

AUDIO_U8

§

const SILENCE: u8 = 128u8

§

fn audio_format() -> AudioFormat

§

impl AudioFormatNum for u16

AUDIO_U16

§

const SILENCE: u16 = 32_768u16

§

fn audio_format() -> AudioFormat

Implementors§