libmirage 0.1.0

Rust bindings for libMirage
Documentation
use glib::prelude::*;
use glib::translate::*;

#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "MirageError")]
pub enum Error {
    #[doc(alias = "MIRAGE_ERROR_LIBRARY_ERROR")]
    LibraryError,
    #[doc(alias = "MIRAGE_ERROR_PARSER_ERROR")]
    ParserError,
    #[doc(alias = "MIRAGE_ERROR_FRAGMENT_ERROR")]
    FragmentError,
    #[doc(alias = "MIRAGE_ERROR_DISC_ERROR")]
    DiscError,
    #[doc(alias = "MIRAGE_ERROR_LANGUAGE_ERROR")]
    LanguageError,
    #[doc(alias = "MIRAGE_ERROR_SECTOR_ERROR")]
    SectorError,
    #[doc(alias = "MIRAGE_ERROR_SESSION_ERROR")]
    SessionError,
    #[doc(alias = "MIRAGE_ERROR_TRACK_ERROR")]
    TrackError,
    #[doc(alias = "MIRAGE_ERROR_STREAM_ERROR")]
    StreamError,
    #[doc(alias = "MIRAGE_ERROR_IMAGE_FILE_ERROR")]
    ImageFileError,
    #[doc(alias = "MIRAGE_ERROR_DATA_FILE_ERROR")]
    DataFileError,
    #[doc(alias = "MIRAGE_ERROR_CANNOT_HANDLE")]
    CannotHandle,
    #[doc(alias = "MIRAGE_ERROR_ENCRYPTED_IMAGE")]
    EncryptedImage,
    #[doc(alias = "MIRAGE_ERROR_WRITER_ERROR")]
    WriterError,
    #[doc(hidden)]
    __Unknown(i32),
}

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

    fn into_glib(self) -> ffi::MirageErrorCode {
        match self {
            Self::LibraryError => ffi::MIRAGE_ERROR_LIBRARY_ERROR,
            Self::ParserError => ffi::MIRAGE_ERROR_PARSER_ERROR,
            Self::FragmentError => ffi::MIRAGE_ERROR_FRAGMENT_ERROR,
            Self::DiscError => ffi::MIRAGE_ERROR_DISC_ERROR,
            Self::LanguageError => ffi::MIRAGE_ERROR_LANGUAGE_ERROR,
            Self::SectorError => ffi::MIRAGE_ERROR_SECTOR_ERROR,
            Self::SessionError => ffi::MIRAGE_ERROR_SESSION_ERROR,
            Self::TrackError => ffi::MIRAGE_ERROR_TRACK_ERROR,
            Self::StreamError => ffi::MIRAGE_ERROR_STREAM_ERROR,
            Self::ImageFileError => ffi::MIRAGE_ERROR_IMAGE_FILE_ERROR,
            Self::DataFileError => ffi::MIRAGE_ERROR_DATA_FILE_ERROR,
            Self::CannotHandle => ffi::MIRAGE_ERROR_CANNOT_HANDLE,
            Self::EncryptedImage => ffi::MIRAGE_ERROR_ENCRYPTED_IMAGE,
            Self::WriterError => ffi::MIRAGE_ERROR_WRITER_ERROR,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::MirageErrorCode> for Error {
    unsafe fn from_glib(value: ffi::MirageErrorCode) -> Self {
        skip_assert_initialized!();

        match value {
            ffi::MIRAGE_ERROR_LIBRARY_ERROR => Self::LibraryError,
            ffi::MIRAGE_ERROR_PARSER_ERROR => Self::ParserError,
            ffi::MIRAGE_ERROR_FRAGMENT_ERROR => Self::FragmentError,
            ffi::MIRAGE_ERROR_DISC_ERROR => Self::DiscError,
            ffi::MIRAGE_ERROR_LANGUAGE_ERROR => Self::LanguageError,
            ffi::MIRAGE_ERROR_SECTOR_ERROR => Self::SectorError,
            ffi::MIRAGE_ERROR_SESSION_ERROR => Self::SessionError,
            ffi::MIRAGE_ERROR_TRACK_ERROR => Self::TrackError,
            ffi::MIRAGE_ERROR_STREAM_ERROR => Self::StreamError,
            ffi::MIRAGE_ERROR_IMAGE_FILE_ERROR => Self::ImageFileError,
            ffi::MIRAGE_ERROR_DATA_FILE_ERROR => Self::DataFileError,
            ffi::MIRAGE_ERROR_CANNOT_HANDLE => Self::CannotHandle,
            ffi::MIRAGE_ERROR_ENCRYPTED_IMAGE => Self::EncryptedImage,
            ffi::MIRAGE_ERROR_WRITER_ERROR => Self::WriterError,
            value => Self::__Unknown(value),
        }
    }
}

impl glib::error::ErrorDomain for Error {
    #[inline]
    fn domain() -> glib::Quark {
        skip_assert_initialized!();

        unsafe { from_glib(ffi::mirage_error_quark()) }
    }

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

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

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

impl glib::HasParamSpec for Error {
    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 Error {
    type Type = Self;
}

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

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

impl ToValue for Error {
    #[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<Error> for glib::Value {
    #[inline]
    fn from(v: Error) -> Self {
        skip_assert_initialized!();
        ToValue::to_value(&v)
    }
}