1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use core::{fmt, fmt::Display};

/// Errors that can occur upon type checking function signatures.
#[derive(Debug)]
pub enum FuncError {
    /// The exported function could not be found.
    ExportedFuncNotFound,
    /// A function parameter did not match the required type.
    MismatchingParameterType,
    /// Specified an incorrect number of parameters.
    MismatchingParameterLen,
    /// A function result did not match the required type.
    MismatchingResultType,
    /// Specified an incorrect number of results.
    MismatchingResultLen,
}

#[cfg(feature = "std")]
impl std::error::Error for FuncError {}

impl Display for FuncError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            FuncError::ExportedFuncNotFound => {
                write!(f, "could not find exported function")
            }
            FuncError::MismatchingParameterType => {
                write!(f, "encountered incorrect function parameter type")
            }
            FuncError::MismatchingParameterLen => {
                write!(f, "encountered an incorrect number of parameters")
            }
            FuncError::MismatchingResultType => {
                write!(f, "encountered incorrect function result type")
            }
            FuncError::MismatchingResultLen => {
                write!(f, "encountered an incorrect number of results")
            }
        }
    }
}