metacall/types/
metacall_error.rs1use super::MetaCallValue;
2use std::{
3 ffi::{c_int, NulError},
4 fmt,
5 path::PathBuf,
6};
7
8#[derive(Debug, Clone)]
9pub struct MetaCallInitError(c_int);
12impl MetaCallInitError {
13 #[doc(hidden)]
14 pub fn new(code: c_int) -> Self {
15 Self(code)
16 }
17}
18impl fmt::Display for MetaCallInitError {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 write!(f, "Failed to initialize MetaCall with code: {}", self.0)
21 }
22}
23
24#[derive(Debug, Clone)]
25pub struct MetaCallStringConversionError {
28 pub original_string: String,
29 pub nul_error: NulError,
30}
31impl MetaCallStringConversionError {
32 #[doc(hidden)]
33 pub fn new(original_string: impl ToString, nul_error: NulError) -> Self {
34 Self {
35 original_string: original_string.to_string(),
36 nul_error,
37 }
38 }
39}
40impl fmt::Display for MetaCallStringConversionError {
41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42 write!(
43 f,
44 "Failed to convert string: {}",
45 self.original_string.clone()
46 )
47 }
48}
49
50#[derive(Debug, Clone)]
51pub enum MetaCallError {
53 FunctionNotFound,
55 FailedCasting(Box<dyn MetaCallValue>),
57 UnexpectedCStringConversionErr(MetaCallStringConversionError),
59}
60
61#[derive(Debug, Clone)]
62pub enum MetaCallSetAttributeError {
65 SetAttributeFailure,
67 UnexpectedCStringConversionErr(MetaCallStringConversionError),
69}
70
71#[derive(Debug, Clone)]
72pub enum MetaCallGetAttributeError {
74 FailedCasting(Box<dyn MetaCallValue>),
76 UnexpectedCStringConversionErr(MetaCallStringConversionError),
78}
79
80#[derive(Debug, Clone)]
81pub enum MetaCallLoaderError {
84 FileNotFound(PathBuf),
86 FromFileFailure,
88 FromMemoryFailure,
90 NotAFileOrPermissionDenied(PathBuf),
92 UnexpectedCStringConversionErr(MetaCallStringConversionError),
94}
95
96#[derive(Debug, Clone)]
97pub enum MetaCallClassFromNameError {
99 ClassNotFound,
101 UnexpectedCStringConversionErr(MetaCallStringConversionError),
103}