1use crate::{Any, Arc};
2
3#[pen_ffi_macro::into_any(crate = "crate", into_fn = "pen_ffi_error_to_any")]
4#[repr(C)]
5#[derive(Clone)]
6pub struct Error(Arc<ErrorInner>);
7
8#[repr(C)]
9struct ErrorInner {
10 source: Any,
11}
12
13impl Error {
14 pub fn new(source: impl Into<Any>) -> Self {
15 Self(
16 ErrorInner {
17 source: source.into(),
18 }
19 .into(),
20 )
21 }
22}
23
24#[cfg(feature = "std")]
25impl<T: std::error::Error> From<T> for Error {
26 fn from(error: T) -> Self {
27 use alloc::string::ToString;
28
29 Self::new(crate::ByteString::from(error.to_string()))
30 }
31}