pub struct Error {
pub kind: ErrorKind,
pub context: Option<Box<RequestContext>>,
/* private fields */
}Expand description
结构化通信错误与请求上下文。 结构化通信错误与请求上下文。 结构化通信错误与请求上下文。 拥有型错误;Clone 共享底层原因及原始帧,协议说明和上下文中的拥有型字符串会复制。
Fields§
§kind: ErrorKind可结构化匹配的类别。
context: Option<Box<RequestContext>>请求相关错误的有界上下文。
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(kind: ErrorKind) -> Self
pub fn new(kind: ErrorKind) -> Self
创建无底层原因的分类错误,不发生 IO。
use ydp_core::{Error, ErrorKind};
let error = Error::new(ErrorKind::Timeout);
assert!(matches!(error.kind, ErrorKind::Timeout));Sourcepub fn with_source(
kind: ErrorKind,
source: impl Error + Send + Sync + 'static,
) -> Self
pub fn with_source( kind: ErrorKind, source: impl Error + Send + Sync + 'static, ) -> Self
保留类型化底层原因;默认 Debug 不展开原因,避免暴露传输凭据。
use ydp_core::{Error, ErrorKind};
let error = Error::with_source(ErrorKind::Transport, std::io::Error::other("失败"));
assert!(std::error::Error::source(&error).is_some());Trait Implementations§
Source§impl Error for Error
impl Error for Error
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 !Freeze for Error
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
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