Struct Error

Source
#[repr(transparent)]
pub struct Error { pub errno: i32, }
Expand description

错误码有两种使用场景:

  1. 需要区分具体错误码: 比如底层target提供接口,需要调用者显示区分target
  2. 无需区分具体错误码: 一般有高层次,粗粒度的容错处理机制,错误码用于日志输出. 对于后一种场景,调用者决定日志输出方式,因此接口的返回值也多使用Result<T, Error>. 这里就会存在Error具体取值的构造尽可能和Target无关,因此为此场景定义了几个常用业务下需要使用到的错误码:
  3. Error::inval
  4. Error::noent
  5. Error::perm
  6. Error::nomem
  7. Error::busy
  8. Error::timedout
  9. Error::general 借用Target定义的错误码来表达业务层的常见错误. 因为此场景并不鼓励基于具体错误码进行容错处理,因此并不提供对应的is_***接口.

Fields§

§errno: i32

Implementations§

Source§

impl Error

Source

pub const fn new(errno: i32) -> Self

Source

pub fn last() -> Self

Source

pub const fn inval() -> Self

表示输入错误. 适用于业务层主动返回错误码,避免使用具体数字导致跨平台兼容问题.

Source

pub const fn noent() -> Self

表示资源不存在. 适用于业务层主动返回错误码,避免使用具体数字导致跨平台兼容问题.

Source

pub const fn perm() -> Self

表示权限不足. 适用于业务层主动返回错误码,避免使用具体数字导致跨平台兼容问题.

Source

pub const fn nomem() -> Self

表示内存不足. 适用于业务层主动返回错误码,避免使用具体数字导致跨平台兼容问题.

Source

pub const fn busy() -> Self

表示繁忙(内部资源受限)返回. 适用于业务层主动返回错误码,避免使用具体数字导致跨平台兼容问题.

Source

pub const fn timedout() -> Self

表示超时返回. 适用于业务层主动返回错误码,避免使用具体数字导致跨平台兼容问题.

Source

pub const fn general() -> Self

表示难以归类的通用错误. 适用于业务层主动返回错误码,避免使用具体数字导致跨平台兼容问题.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

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

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

impl Default for Error

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Error

Source§

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

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

impl From<Error> for Result<()>

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Error

Source§

fn from(i32: i32) -> Self

Converts to this type from the input type.
Source§

impl Ord for Error

Source§

fn cmp(&self, other: &Error) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Error

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Error

Source§

fn partial_cmp(&self, other: &Error) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Error

Source§

impl Eq for Error

Source§

impl StructuralPartialEq for Error

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnwindSafe for Error

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> 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, 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.