1use foreign_types::ForeignType;
2use std::error::Error as StdError;
3use std::fmt;
4
5#[derive(Debug, Copy, Clone, Eq, PartialEq)]
6pub enum Error {
7 ObjectCreationError,
8 MissingData,
9 InvalidString,
10}
11
12impl Error {
13 #[inline]
14 pub(crate) unsafe fn if_null<T>(handle: *mut <T as ForeignType>::CType) -> LCMSResult<T> where T: ForeignType {
15 if !handle.is_null() {
16 Ok(T::from_ptr(handle))
17 } else {
18 Err(Error::ObjectCreationError)
19 }
20 }
21}
22
23pub type LCMSResult<T> = Result<T, Error>;
25
26impl fmt::Display for Error {
27 #[cold]
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 f.write_str(match *self {
30 Error::ObjectCreationError => "Could not create the object.\nThe reason is not known, but it's usually caused by wrong input parameters.",
31 Error::InvalidString => "String is not valid. Contains unsupported characters or is too long.",
32 Error::MissingData => "Requested data is empty or does not exist.",
33 })
34 }
35}
36
37impl StdError for Error {
38}