pub struct ErrorContext { /* private fields */ }Expand description
现代化错误上下文
提供丰富的错误上下文信息,支持结构化数据和链式错误追踪
Implementations§
Source§impl ErrorContext
impl ErrorContext
Sourcepub fn with_user_message(message: impl Into<String>) -> Self
pub fn with_user_message(message: impl Into<String>) -> Self
创建带有用户消息的错误上下文
Sourcepub fn with_operation(operation: impl Into<String>) -> Self
pub fn with_operation(operation: impl Into<String>) -> Self
创建带有操作名的错误上下文
Sourcepub fn set_user_message(&mut self, message: impl Into<String>)
pub fn set_user_message(&mut self, message: impl Into<String>)
设置用户友好消息
Sourcepub fn user_message(&self) -> Option<&str>
pub fn user_message(&self) -> Option<&str>
获取用户友好消息
Sourcepub fn add_context(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> &mut Self
pub fn add_context( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self
添加上下文信息
Sourcepub fn extend_context<I, K, V>(&mut self, iter: I) -> &mut Self
pub fn extend_context<I, K, V>(&mut self, iter: I) -> &mut Self
批量添加上下文信息
Sourcepub fn get_context(&self, key: &str) -> Option<&str>
pub fn get_context(&self, key: &str) -> Option<&str>
获取上下文值
Sourcepub fn all_context(&self) -> &HashMap<String, String>
pub fn all_context(&self) -> &HashMap<String, String>
获取所有上下文信息
Sourcepub fn has_context(&self, key: &str) -> bool
pub fn has_context(&self, key: &str) -> bool
检查是否有指定的上下文键
Sourcepub fn set_request_id(&mut self, request_id: impl Into<String>) -> &mut Self
pub fn set_request_id(&mut self, request_id: impl Into<String>) -> &mut Self
设置请求ID
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
获取请求ID
Sourcepub fn set_operation(&mut self, operation: impl Into<String>) -> &mut Self
pub fn set_operation(&mut self, operation: impl Into<String>) -> &mut Self
设置操作名称
Sourcepub fn set_component(&mut self, component: impl Into<String>) -> &mut Self
pub fn set_component(&mut self, component: impl Into<String>) -> &mut Self
设置组件名称
Sourcepub fn timestamp(&self) -> Option<SystemTime>
pub fn timestamp(&self) -> Option<SystemTime>
获取时间戳
Sourcepub fn clear_context(&mut self)
pub fn clear_context(&mut self)
清空所有上下文信息 清空所有上下文信息
Sourcepub fn context_len(&self) -> usize
pub fn context_len(&self) -> usize
获取上下文信息数量
Sourcepub fn debug_format(&self) -> String
pub fn debug_format(&self) -> String
转换为调试格式
Sourcepub fn clone_with(&self) -> Self
pub fn clone_with(&self) -> Self
从当前上下文创建副本,并可以添加额外信息
Trait Implementations§
Source§impl Clone for ErrorContext
impl Clone for ErrorContext
Source§fn clone(&self) -> ErrorContext
fn clone(&self) -> ErrorContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ErrorContext
impl Debug for ErrorContext
Source§impl Default for ErrorContext
impl Default for ErrorContext
Source§impl Display for ErrorContext
impl Display for ErrorContext
Source§impl ErrorContextTrait for ErrorContext
impl ErrorContextTrait for ErrorContext
Source§fn user_message(&self) -> Option<&str>
fn user_message(&self) -> Option<&str>
获取用户友好消息
Source§fn request_id(&self) -> Option<&str>
fn request_id(&self) -> Option<&str>
获取请求ID
Source§fn has_context(&self, key: &str) -> bool
fn has_context(&self, key: &str) -> bool
检查是否有指定的上下文键
Auto Trait Implementations§
impl Freeze for ErrorContext
impl RefUnwindSafe for ErrorContext
impl Send for ErrorContext
impl Sync for ErrorContext
impl Unpin for ErrorContext
impl UnsafeUnpin for ErrorContext
impl UnwindSafe for ErrorContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.