1use alloc::borrow::ToOwned;
2use core::fmt;
3use sys::ffi::CStr;
4use sys::ffi::CString;
5
6
7pub type ApiError = sys::error::Error<self::Error>;
8
9
10#[derive(Debug)]
11pub enum Error {
12 AddFunction(CString),
13}
14
15impl fmt::Display for Error {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 match &self {
18 Error::AddFunction(cs) => {
19 match cs.to_str() {
20 Ok(err) => err.fmt(f),
21 Err(_) => f.write_fmt(format_args!("Add function error: {cs:?}")),
22 }
23 },
24 }
25 }
26}
27
28
29impl From<Error> for ApiError {
30 fn from(err: Error) -> Self { ApiError::Api(err) }
31}
32
33impl From<&'_ CStr> for Error {
34 fn from(cs: &CStr) -> Self { Self::AddFunction(cs.to_owned()) }
35}
36
37
38impl core::error::Error for Error {}