ParseError

Enum ParseError 

Source
pub enum ParseError {
    MissingFields(usize),
    Int(ParseIntError),
    Float(ParseFloatError),
    InvalidFormat,
}
Expand description

解析错误类型

说明:该枚举表示在将日志字段从字符串解析为数字或其他期望格式时可能发生的错误。 我们把常见的错误包装成特定变体,便于上层调用者进行匹配、报告或恢复处理。

  • MissingFields(usize):当解析时发现字段数量不足(例如缺少期望的元数据项)时使用;携带期望字段数用于诊断;
  • Int(ParseIntError):整数解析失败的包装(保留原始 ParseIntError 以便追踪来源);
  • Float(ParseFloatError):浮点数解析失败的包装;
  • InvalidFormat:通用格式错误,用于无法归类或发现奇怪格式时的占位错误。

Variants§

§

MissingFields(usize)

§

Int(ParseIntError)

§

Float(ParseFloatError)

§

InvalidFormat

Trait Implementations§

Source§

impl Debug for ParseError

Source§

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

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

impl Display for ParseError

Source§

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

为 ParseError 提供可读的错误信息,方便在日志或用户界面中直接打印。

目的:实现 Display 可以让错误在使用 eprintln!format!println! 时显示更友好的文本。 同时,Display 不丢弃底层错误的信息;Error::source() 会指向原始的解析错误(若有),以便链式错误追踪。

Source§

impl Error for ParseError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

返回底层错误以支持错误链(source),这对于调试和日志记录很有用。 例如,当 ParseIntError 发生时,source() 会返回原始的 ParseIntError,调用方可以通过它获取更多上下文。

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 From<ParseFloatError> for ParseError

Source§

fn from(e: ParseFloatError) -> Self

Converts to this type from the input type.
Source§

impl From<ParseIntError> for ParseError

为方便使用 ? 操作符,将标准库的解析错误转换为 ParseError

解释:实现 From<ParseIntError> / From<ParseFloatError> 能让在解析整数/浮点数时直接使用 ?, 并自动将底层错误转换为本 crate 的统一错误类型,简化上层错误传播逻辑。

Source§

fn from(e: ParseIntError) -> Self

Converts to this type from the input type.

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> 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<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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.