diff options
Diffstat (limited to 'crates/libmpv2/src/mpv/errors.rs')
-rw-r--r-- | crates/libmpv2/src/mpv/errors.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/crates/libmpv2/src/mpv/errors.rs b/crates/libmpv2/src/mpv/errors.rs index a2baee5..4b28fb3 100644 --- a/crates/libmpv2/src/mpv/errors.rs +++ b/crates/libmpv2/src/mpv/errors.rs @@ -8,36 +8,45 @@ // You should have received a copy of the License along with this program. // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. -use std::{ffi::NulError, os::raw as ctype, str::Utf8Error}; - -use thiserror::Error; +use std::{ffi::NulError, fmt::Display, os::raw as ctype, str::Utf8Error}; use super::mpv_error; #[allow(missing_docs)] pub type Result<T> = ::std::result::Result<T, Error>; -#[derive(Error, Debug)] +#[derive(Debug)] pub enum Error { - #[error("loading file failed: {error}")] - Loadfile { error: String }, + Loadfile { + error: String, + }, - #[error("version mismatch detected! Linked version ({linked}) is unequal to the loaded version ({loaded})")] VersionMismatch { linked: ctype::c_ulong, loaded: ctype::c_ulong, }, - #[error("invalid utf8 returned")] InvalidUtf8, - #[error("null pointer returned")] Null, - #[error("raw error returned: {}", to_string_mpv_error(*(.0)))] Raw(crate::MpvError), } +impl std::error::Error for Error {} + +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::Loadfile { error } => write!(f, "loading file failed: {error}"), + Error::VersionMismatch { linked, loaded } => write!(f, "version mismatch detected! Linked version ({linked}) is unequal to the loaded version ({loaded})"), + Error::InvalidUtf8 => f.write_str("invalid utf8 returned"), + Error::Null => f.write_str("null pointer returned"), + Error::Raw(raw) => write!(f, include_str!("./raw_error_warning.txt"), to_string_mpv_error(*(raw))), + } + } +} + impl From<NulError> for Error { fn from(_other: NulError) -> Error { Error::Null |