pub struct CalcError {
pub kind: ErrorKind,
pub message: String,
pub span: Option<Span>,
pub hint: Option<String>,
pub hint_i18n_key: Option<&'static str>,
pub hint_i18n_args: Vec<(String, String)>,
pub source_detail: Option<String>,
pub i18n_key: Option<&'static str>,
pub i18n_args: Vec<(String, String)>,
}Expand description
计算错误:kind + message + span + hint + i18n;Display/to_json 始终用 message 保持机器契约。
Fields§
§kind: ErrorKind§message: String§span: Option<Span>§hint: Option<String>§hint_i18n_key: Option<&'static str>hint 的 i18n 键+参数:friendly()/to_explain() 用其替换 hint,to_json() 用原始 hint。
hint_i18n_args: Vec<(String, String)>§source_detail: Option<String>底层错误链:Display 呈现 “{message}: {source}”;字段名避开 source(thiserror 占用)。
i18n_key: Option<&'static str>§i18n_args: Vec<(String, String)>Implementations§
Source§impl CalcError
impl CalcError
pub fn new(kind: ErrorKind, message: impl Into<String>) -> Self
Sourcepub fn with_source(self, source: impl Into<String>) -> Self
pub fn with_source(self, source: impl Into<String>) -> Self
附加底层错误摘要(错误链)。
Sourcepub fn source_text(&self) -> Option<&str>
pub fn source_text(&self) -> Option<&str>
底层错误摘要(错误链访问器)。
pub fn with_span(self, span: Span) -> Self
pub fn with_hint(self, hint: impl Into<String>) -> Self
Sourcepub fn with_hint_i18n(
self,
key: &'static str,
args: Vec<(String, String)>,
) -> Self
pub fn with_hint_i18n( self, key: &'static str, args: Vec<(String, String)>, ) -> Self
附加 hint 的 i18n 键+参数(链式):to_json() 与 Display 不受影响。
Sourcepub fn with_i18n(self, key: &'static str, args: Vec<(String, String)>) -> Self
pub fn with_i18n(self, key: &'static str, args: Vec<(String, String)>) -> Self
附加国际化消息键+参数(链式):friendly()/to_explain() 用其替换 message。
pub fn parse(msg: impl Into<String>) -> Self
pub fn eval(msg: impl Into<String>) -> Self
pub fn overflow() -> Self
pub fn nan_or_inf() -> Self
pub fn domain(msg: impl Into<String>) -> Self
pub fn depth_exceeded() -> Self
pub fn division_by_zero() -> Self
上游依赖不可用错误。
pub fn undefined_symbol(name: &str) -> Self
pub fn timeout() -> Self
pub fn usage(msg: impl Into<String>) -> Self
Sourcepub fn friendly(&self, i18n: &I18n) -> String
pub fn friendly(&self, i18n: &I18n) -> String
按 i18n 本地化的友好文本(终端展示):detail 优先走 i18n_key+i18n_args,缺省英文。
Sourcepub fn localized_display(&self, i18n: &I18n) -> String
pub fn localized_display(&self, i18n: &I18n) -> String
batch 文本 sink 的单行本地化错误行:zh 走目录渲染(不含 source_detail),en 与 Display 一致;不含 span/hint(单行契约)。
Sourcepub fn to_explain(&self, i18n: &I18n) -> String
pub fn to_explain(&self, i18n: &I18n) -> String
教育模式(–explain)。
Trait Implementations§
Source§impl Error for CalcError
impl Error for CalcError
1.30.0 · 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()
impl StructuralPartialEq for CalcError
Auto Trait Implementations§
impl Forget for CalcError
impl Freeze for CalcError
impl Move for CalcError
impl RefUnwindSafe for CalcError
impl Send for CalcError
impl Sync for CalcError
impl Unpin for CalcError
impl UnsafeUnpin for CalcError
impl UnwindSafe for CalcError
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.