pub struct OpaqueErrorSource(/* private fields */);Expand description
Opaque handle to an underlying error, preserving its source chain without exposing the concrete type.
The opacity contract: the pointee is reachable only through
std::error::Error::source() (returned directly — no Arc wrapper hop),
the inner handle is private, there is no public Clone, and provenance
cannot be extracted outside camel-api (short of unsafe). Crate internals
duplicate the handle via OpaqueErrorSource::clone_handle when cloning a
CamelError.
§Examples
The inner handle cannot be destructured out of the wrapper (private field):
ⓘ
use camel_api::OpaqueErrorSource;
#[derive(Debug)]
struct MyError;
impl std::fmt::Display for MyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("my error")
}
}
impl std::error::Error for MyError {}
let OpaqueErrorSource(inner) = OpaqueErrorSource::new(std::sync::Arc::new(MyError));The wrapper is deliberately not Clone, so callers cannot copy the handle
out of camel-api:
ⓘ
use camel_api::OpaqueErrorSource;
#[derive(Debug)]
struct MyError;
impl std::fmt::Display for MyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("my error")
}
}
impl std::error::Error for MyError {}
let s = OpaqueErrorSource::new(std::sync::Arc::new(MyError));
let _ = s.clone();Implementations§
Trait Implementations§
Source§impl Debug for OpaqueErrorSource
impl Debug for OpaqueErrorSource
Source§impl Display for OpaqueErrorSource
impl Display for OpaqueErrorSource
Source§impl Error for OpaqueErrorSource
impl Error for OpaqueErrorSource
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl !RefUnwindSafe for OpaqueErrorSource
impl !UnwindSafe for OpaqueErrorSource
impl Freeze for OpaqueErrorSource
impl Send for OpaqueErrorSource
impl Sync for OpaqueErrorSource
impl Unpin for OpaqueErrorSource
impl UnsafeUnpin for OpaqueErrorSource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more