Skip to main content

CalcError

Struct CalcError 

Source
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

Source

pub fn new(kind: ErrorKind, message: impl Into<String>) -> Self

Source

pub fn with_source(self, source: impl Into<String>) -> Self

附加底层错误摘要(错误链)。

Source

pub fn source_text(&self) -> Option<&str>

底层错误摘要(错误链访问器)。

Source

pub fn with_span(self, span: Span) -> Self

Source

pub fn with_hint(self, hint: impl Into<String>) -> Self

Source

pub fn with_hint_i18n( self, key: &'static str, args: Vec<(String, String)>, ) -> Self

附加 hint 的 i18n 键+参数(链式):to_json() 与 Display 不受影响。

Source

pub fn with_i18n(self, key: &'static str, args: Vec<(String, String)>) -> Self

附加国际化消息键+参数(链式):friendly()/to_explain() 用其替换 message。

Source

pub fn parse(msg: impl Into<String>) -> Self

Source

pub fn eval(msg: impl Into<String>) -> Self

Source

pub fn overflow() -> Self

Source

pub fn nan_or_inf() -> Self

Source

pub fn domain(msg: impl Into<String>) -> Self

Source

pub fn depth_exceeded() -> Self

Source

pub fn division_by_zero() -> Self

Source

pub fn dependency_unavailable(message: impl Into<String>) -> Self

上游依赖不可用错误。

Source

pub fn undefined_symbol(name: &str) -> Self

Source

pub fn timeout() -> Self

Source

pub fn usage(msg: impl Into<String>) -> Self

Source

pub fn friendly(&self, i18n: &I18n) -> String

按 i18n 本地化的友好文本(终端展示):detail 优先走 i18n_key+i18n_args,缺省英文。

Source

pub fn localized_display(&self, i18n: &I18n) -> String

batch 文本 sink 的单行本地化错误行:zh 走目录渲染(不含 source_detail),en 与 Display 一致;不含 span/hint(单行契约)。

Source

pub fn to_json(&self) -> String

JSON 机器可读输出(--json)。

Source

pub fn to_explain(&self, i18n: &I18n) -> String

教育模式(–explain)。

Trait Implementations§

Source§

impl Clone for CalcError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CalcError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for CalcError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for CalcError

1.30.0 · Source§

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

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for CalcError

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CalcError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.