1use std::io;
18use thiserror::Error;
19
20#[derive(Debug, Error)]
21#[non_exhaustive]
22pub enum Error {
23 #[error("Error: {:?}", .0)]
24 Other(String),
25 #[error("IOError: {:?}", .0)]
26 IoError(#[from] io::Error),
27 #[error("FromUtf8Error: {:?}", .0)]
28 FromUtf8Error(#[from] std::string::FromUtf8Error),
29 #[error("UrdfError: {:?}", .0)]
30 Urdf(#[from] urdf_rs::UrdfError),
31}
32
33pub type Result<T> = ::std::result::Result<T, Error>;
34
35impl<'a> From<&'a str> for Error {
36 fn from(error: &'a str) -> Self {
37 Error::Other(error.to_owned())
38 }
39}
40
41impl From<String> for Error {
42 fn from(error: String) -> Self {
43 Error::Other(error)
44 }
45}
46
47#[cfg(target_family = "wasm")]
48impl From<wasm_bindgen::JsValue> for Error {
49 fn from(error: wasm_bindgen::JsValue) -> Self {
50 Error::Other(format!("{error:?}"))
51 }
52}
53
54#[cfg(target_family = "wasm")]
55impl From<Error> for wasm_bindgen::JsValue {
56 fn from(error: Error) -> Self {
57 Self::from_str(&error.to_string())
58 }
59}