pub struct OneErr(/* private fields */);
Expand description

OneErr to rule them all. See crate docs for usage.

Implementations§

§

impl OneErr

pub fn new<K>(kind: K) -> OneErr
where K: Display,

Create a new OneErr error instance.

pub fn with_message<K, M>(kind: K, message: M) -> OneErr
where K: Display, M: Display,

Create a new OneErr error instance with a message.

pub fn io_kind(&self) -> ErrorKind

Get the std::io::ErrorKind associated with this instance.

pub fn errno(&self) -> ErrNo

Get the ErrNo associated with this instance, if any.

pub fn str_kind(&self) -> &str

Get the &str kind associated with this instance. This can be more descriptive where io_kind() or errno() might return ‘Other’.

pub fn as_io(&self) -> &Error

Get a reference to the inner std::io::Error of this instance.

pub fn set_field<K, T>(&mut self, name: &K, t: T) -> &mut OneErr
where K: Display + ?Sized, T: Into<Value>,

Set an additional data field on this OneErr. Will panic on reserved names: “error”, “os”, “source”, “backtrace”, “message”.

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

Get the message associated with this instance, or empty string.

pub fn get_field<'lt, R, V>(&'lt self, name: R) -> Option<V>
where R: AsRef<str>, Option<V>: From<&'lt Value>,

Get the value of an additional field associated with this error, or None if no such field exists. Valid output types: &str, bool, i64, u64, and f64.

Methods from Deref<Target = Error>§

1.0.0 · source

pub fn raw_os_error(&self) -> Option<i32>

Returns the OS error that this error represents (if any).

If this Error was constructed via last_os_error or from_raw_os_error, then this function will return Some, otherwise it will return None.

§Examples
use std::io::{Error, ErrorKind};

fn print_os_error(err: &Error) {
    if let Some(raw_os_err) = err.raw_os_error() {
        println!("raw OS error: {raw_os_err:?}");
    } else {
        println!("Not an OS error");
    }
}

fn main() {
    // Will print "raw OS error: ...".
    print_os_error(&Error::last_os_error());
    // Will print "Not an OS error".
    print_os_error(&Error::new(ErrorKind::Other, "oh no!"));
}
1.3.0 · source

pub fn get_ref(&self) -> Option<&(dyn Error + Send + Sync + 'static)>

Returns a reference to the inner error wrapped by this error (if any).

If this Error was constructed via new then this function will return Some, otherwise it will return None.

§Examples
use std::io::{Error, ErrorKind};

fn print_error(err: &Error) {
    if let Some(inner_err) = err.get_ref() {
        println!("Inner error: {inner_err:?}");
    } else {
        println!("No inner error");
    }
}

fn main() {
    // Will print "No inner error".
    print_error(&Error::last_os_error());
    // Will print "Inner error: ...".
    print_error(&Error::new(ErrorKind::Other, "oh no!"));
}
1.0.0 · source

pub fn kind(&self) -> ErrorKind

Returns the corresponding ErrorKind for this error.

This may be a value set by Rust code constructing custom io::Errors, or if this io::Error was sourced from the operating system, it will be a value inferred from the system’s error encoding. See last_os_error for more details.

§Examples
use std::io::{Error, ErrorKind};

fn print_error(err: Error) {
    println!("{:?}", err.kind());
}

fn main() {
    // As no error has (visibly) occurred, this may print anything!
    // It likely prints a placeholder for unidentified (non-)errors.
    print_error(Error::last_os_error());
    // Will print "AddrInUse".
    print_error(Error::new(ErrorKind::AddrInUse, "oh no!"));
}

Trait Implementations§

§

impl AsRef<Error> for OneErr

§

fn as_ref(&self) -> &Error

Converts this type into a shared reference of the (usually inferred) input type.
§

impl Clone for OneErr

§

fn clone(&self) -> OneErr

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
§

impl Debug for OneErr

§

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

Formats the value using the given formatter. Read more
§

impl Deref for OneErr

§

type Target = Error

The resulting type after dereferencing.
§

fn deref(&self) -> &<OneErr as Deref>::Target

Dereferences the value.
§

impl<'de> Deserialize<'de> for OneErr

§

fn deserialize<D>( deserializer: D ) -> Result<OneErr, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for OneErr

§

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

Formats the value using the given formatter. Read more
§

impl Error for OneErr

1.30.0 · source§

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

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
§

impl From<&OneErr> for Error

§

fn from(e: &OneErr) -> Error

Converts to this type from the input type.
§

impl From<&OneErr> for SodokenErrKind

§

fn from(e: &OneErr) -> SodokenErrKind

Converts to this type from the input type.
§

impl From<&String> for OneErr

§

fn from(s: &String) -> OneErr

Converts to this type from the input type.
§

impl From<&str> for OneErr

§

fn from(s: &str) -> OneErr

Converts to this type from the input type.
§

impl From<()> for OneErr

§

fn from(_: ()) -> OneErr

Converts to this type from the input type.
§

impl From<ErrNo> for OneErr

§

fn from(e: ErrNo) -> OneErr

Converts to this type from the input type.
§

impl From<Error> for OneErr

§

fn from(e: Error) -> OneErr

Converts to this type from the input type.
§

impl From<ErrorKind> for OneErr

§

fn from(k: ErrorKind) -> OneErr

Converts to this type from the input type.
§

impl From<OneErr> for Error

§

fn from(e: OneErr) -> Error

Converts to this type from the input type.
§

impl From<SodokenErrKind> for OneErr

§

fn from(k: SodokenErrKind) -> OneErr

Converts to this type from the input type.
§

impl From<String> for OneErr

§

fn from(s: String) -> OneErr

Converts to this type from the input type.
§

impl From<i32> for OneErr

§

fn from(e: i32) -> OneErr

Converts to this type from the input type.
§

impl FromStr for OneErr

§

type Err = OneErr

The associated error which can be returned from parsing.
§

fn from_str(s: &str) -> Result<OneErr, <OneErr as FromStr>::Err>

Parses a string s to return a value of this type. Read more
§

impl PartialEq for OneErr

§

fn eq(&self, oth: &OneErr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl Serialize for OneErr

§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Eq for OneErr

Auto Trait Implementations§

§

impl !RefUnwindSafe for OneErr

§

impl Send for OneErr

§

impl Sync for OneErr

§

impl Unpin for OneErr

§

impl !UnwindSafe for OneErr

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

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§

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

§

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

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,