#[non_exhaustive]pub struct Error {
pub kind: ErrorKind,
/* private fields */
}Expand description
Describes an arbitrary error that prevented an operation from completing.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.kind: ErrorKindThe general kind of the error. Code that decides how to respond to an error should read only this field in making its decision.
Implementations§
Source§impl Error
impl Error
pub fn new(kind: ErrorKind, extra: String) -> Self
pub fn from_kind(kind: ErrorKind) -> Self
pub fn failed(description: String) -> Self
pub fn overloaded(description: String) -> Self
pub fn disconnected(description: String) -> Self
pub fn unimplemented(description: String) -> Self
Sourcepub fn extra(&self) -> &str
pub fn extra(&self) -> &str
Returns any extra human-readable context attached to this error, or "" if none.
Sourcepub fn write_fmt(&mut self, fmt: Arguments<'_>)
pub fn write_fmt(&mut self, fmt: Arguments<'_>)
Appends formatted text to this error’s extra context. Does nothing if the "alloc"
feature is not enabled. This is intended to be used with the write!() macro from core.
Sourcepub fn get_detail(&self, detail_id: u64) -> Option<&[u8]>
pub fn get_detail(&self, detail_id: u64) -> Option<&[u8]>
Returns the detail payload associated with detail_id, if present.
Details can be attached to an error returned by an RPC server method and retrieved on the
client after awaiting the call. Each detail type should use a unique 64-bit ID (typically
generated with capnp id).
Sourcepub fn get_details(&self) -> &[ErrorDetail]
pub fn get_details(&self) -> &[ErrorDetail]
Returns all ErrorDetail entries attached to this error.
Sourcepub fn set_detail(&mut self, detail_id: u64, data: Vec<u8>)
pub fn set_detail(&mut self, detail_id: u64, data: Vec<u8>)
Attaches a detail payload keyed by detail_id to this error, replacing any
existing payload with the same detail_id.
Each detail type should use a unique 64-bit ID (typically generated with capnp id).
const VALIDATION_ERROR: u64 = 0x9935_c2b4_7d94_809c;
let mut err = capnp::Error::failed("invalid".into());
err.set_detail(VALIDATION_ERROR, b"field x must be positive".to_vec());
assert_eq!(err.get_detail(VALIDATION_ERROR), Some(&b"field x must be positive"[..]));Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
replaced by Error::source, which can support downcasting
Source§impl From<FromUtf8Error> for Error
Available on crate feature alloc only.
impl From<FromUtf8Error> for Error
alloc only.