alsarawmidi 0.8.0

API binding for alsarawmidi library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::ffi;
use glib::{prelude::*, translate::*};

/// A set of enumerations for the direction of stream.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "ALSARawmidiStreamDirection")]
pub enum StreamDirection {
    #[doc(alias = "ALSARAWMIDI_STREAM_DIRECTION_OUTPUT")]
    Output,
    #[doc(alias = "ALSARAWMIDI_STREAM_DIRECTION_INPUT")]
    Input,
    #[doc(hidden)]
    __Unknown(i32),
}

#[doc(hidden)]
impl IntoGlib for StreamDirection {
    type GlibType = ffi::ALSARawmidiStreamDirection;

    #[inline]
    fn into_glib(self) -> ffi::ALSARawmidiStreamDirection {
        match self {
            Self::Output => ffi::ALSARAWMIDI_STREAM_DIRECTION_OUTPUT,
            Self::Input => ffi::ALSARAWMIDI_STREAM_DIRECTION_INPUT,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::ALSARawmidiStreamDirection> for StreamDirection {
    #[inline]
    unsafe fn from_glib(value: ffi::ALSARawmidiStreamDirection) -> Self {
        match value {
            ffi::ALSARAWMIDI_STREAM_DIRECTION_OUTPUT => Self::Output,
            ffi::ALSARAWMIDI_STREAM_DIRECTION_INPUT => Self::Input,
            value => Self::__Unknown(value),
        }
    }
}

impl StaticType for StreamDirection {
    #[inline]
    #[doc(alias = "alsarawmidi_stream_direction_get_type")]
    fn static_type() -> glib::Type {
        unsafe { from_glib(ffi::alsarawmidi_stream_direction_get_type()) }
    }
}

impl glib::HasParamSpec for StreamDirection {
    type ParamSpec = glib::ParamSpecEnum;
    type SetValue = Self;
    type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;

    fn param_spec_builder() -> Self::BuilderFn {
        Self::ParamSpec::builder_with_default
    }
}

impl glib::value::ValueType for StreamDirection {
    type Type = Self;
}

unsafe impl<'a> glib::value::FromValue<'a> for StreamDirection {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    #[inline]
    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for StreamDirection {
    #[inline]
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    #[inline]
    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

impl From<StreamDirection> for glib::Value {
    #[inline]
    fn from(v: StreamDirection) -> Self {
        ToValue::to_value(&v)
    }
}

/// A set of error code for [`glib::Error`][crate::glib::Error] with `ALSARawmidi.StreamPairError` domain.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "ALSARawmidiStreamPairError")]
pub enum StreamPairError {
    #[doc(alias = "ALSARAWMIDI_STREAM_PAIR_ERROR_FAILED")]
    Failed,
    #[doc(alias = "ALSARAWMIDI_STREAM_PAIR_ERROR_DISCONNECTED")]
    Disconnected,
    #[doc(alias = "ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE")]
    Unreadable,
    #[doc(hidden)]
    __Unknown(i32),
}

#[doc(hidden)]
impl IntoGlib for StreamPairError {
    type GlibType = ffi::ALSARawmidiStreamPairError;

    #[inline]
    fn into_glib(self) -> ffi::ALSARawmidiStreamPairError {
        match self {
            Self::Failed => ffi::ALSARAWMIDI_STREAM_PAIR_ERROR_FAILED,
            Self::Disconnected => ffi::ALSARAWMIDI_STREAM_PAIR_ERROR_DISCONNECTED,
            Self::Unreadable => ffi::ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::ALSARawmidiStreamPairError> for StreamPairError {
    #[inline]
    unsafe fn from_glib(value: ffi::ALSARawmidiStreamPairError) -> Self {
        match value {
            ffi::ALSARAWMIDI_STREAM_PAIR_ERROR_FAILED => Self::Failed,
            ffi::ALSARAWMIDI_STREAM_PAIR_ERROR_DISCONNECTED => Self::Disconnected,
            ffi::ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE => Self::Unreadable,
            value => Self::__Unknown(value),
        }
    }
}

impl glib::error::ErrorDomain for StreamPairError {
    #[inline]
    fn domain() -> glib::Quark {
        unsafe { from_glib(ffi::alsarawmidi_stream_pair_error_quark()) }
    }

    #[inline]
    fn code(self) -> i32 {
        self.into_glib()
    }

    #[inline]
    #[allow(clippy::match_single_binding)]
    fn from(code: i32) -> Option<Self> {
        match unsafe { from_glib(code) } {
            Self::__Unknown(_) => Some(Self::Failed),
            value => Some(value),
        }
    }
}

impl StaticType for StreamPairError {
    #[inline]
    #[doc(alias = "alsarawmidi_stream_pair_error_get_type")]
    fn static_type() -> glib::Type {
        unsafe { from_glib(ffi::alsarawmidi_stream_pair_error_get_type()) }
    }
}

impl glib::HasParamSpec for StreamPairError {
    type ParamSpec = glib::ParamSpecEnum;
    type SetValue = Self;
    type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;

    fn param_spec_builder() -> Self::BuilderFn {
        Self::ParamSpec::builder_with_default
    }
}

impl glib::value::ValueType for StreamPairError {
    type Type = Self;
}

unsafe impl<'a> glib::value::FromValue<'a> for StreamPairError {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    #[inline]
    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for StreamPairError {
    #[inline]
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    #[inline]
    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

impl From<StreamPairError> for glib::Value {
    #[inline]
    fn from(v: StreamPairError) -> Self {
        ToValue::to_value(&v)
    }
}