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
//------------------------------------------------------------------------------
// Luke Titley : from+usd_rs@luketitley.com
//------------------------------------------------------------------------------

/*
pub struct Error {
    pub messages: std::vec::Vec<std::string::String>,
}
*/

#[derive(Debug)]
pub enum Error {
    UnableToRemovePrim,
    UnableToAddReference,
    UnableToDereferencePointer,
    MessageOnly(std::string::String),
    NullError(std::ffi::NulError),
    Utf8(std::str::Utf8Error),
}

impl std::convert::From<std::ffi::NulError> for Error {
    fn from(error: std::ffi::NulError) -> Self {
        Error::NullError(error)
    }
}

impl std::convert::From<&str> for Error {
    fn from(error: &str) -> Self {
        Error::MessageOnly(error.to_string())
    }
}

impl std::convert::From<std::str::Utf8Error> for Error {
    fn from(error: std::str::Utf8Error) -> Self {
        Error::Utf8(error)
    }
}