maudio 0.1.5

Rust bindings to the miniaudio library
Documentation
use maudio_sys::ffi as sys;

use crate::{AsRawRef, ErrorKinds, MaudioError};

struct NodeBuilder {
    inner: sys::ma_node_config,
}

impl AsRawRef for NodeBuilder {
    type Raw = sys::ma_node_config;

    fn as_raw(&self) -> &Self::Raw {
        &self.inner
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub enum NodeState {
    Started,
    Stopped,
}

impl From<NodeState> for sys::ma_node_state {
    fn from(value: NodeState) -> Self {
        match value {
            NodeState::Started => sys::ma_node_state_ma_node_state_started,
            NodeState::Stopped => sys::ma_node_state_ma_node_state_stopped,
        }
    }
}

impl TryFrom<sys::ma_node_state> for NodeState {
    type Error = MaudioError;

    fn try_from(value: sys::ma_pan_mode) -> Result<Self, Self::Error> {
        match value {
            sys::ma_node_state_ma_node_state_started => Ok(NodeState::Started),
            sys::ma_node_state_ma_node_state_stopped => Ok(NodeState::Stopped),
            other => Err(MaudioError::new_ma_error(ErrorKinds::unknown_enum::<
                NodeState,
            >(other as i64))),
        }
    }
}