libmpv/mpv/errors.rs
1// Copyright (C) 2016 ParadoxSpiral
2//
3// This file is part of mpv-rs.
4//
5// This library is free software; you can redistribute it and/or
6// modify it under the terms of the GNU Lesser General Public
7// License as published by the Free Software Foundation; either
8// version 2.1 of the License, or (at your option) any later version.
9//
10// This library is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public
16// License along with this library; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19use std::{error, ffi::NulError, fmt, os::raw as ctype, rc::Rc, str::Utf8Error};
20
21#[allow(missing_docs)]
22pub type Result<T> = ::std::result::Result<T, Error>;
23
24#[derive(Clone, Debug, PartialEq, Eq, Hash)]
25pub enum Error {
26 Loadfiles {
27 index: usize,
28 error: Rc<Error>,
29 },
30 VersionMismatch {
31 linked: ctype::c_ulong,
32 loaded: ctype::c_ulong,
33 },
34 InvalidUtf8,
35 Null,
36 Raw(crate::MpvError),
37}
38
39impl fmt::Display for Error {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
41 write!(f, "{:?}", self)
42 }
43}
44
45impl From<NulError> for Error {
46 fn from(_other: NulError) -> Error {
47 Error::Null
48 }
49}
50
51impl From<Utf8Error> for Error {
52 fn from(_other: Utf8Error) -> Error {
53 Error::InvalidUtf8
54 }
55}
56impl From<crate::MpvError> for Error {
57 fn from(other: crate::MpvError) -> Error {
58 Error::Raw(other)
59 }
60}
61
62impl error::Error for Error {}