[−][src]Enum semeion::error::Error
Represents any possible error.
This enum allows to encode the errors that can be raised by this library as well as allow to encode a custom error, that will need to be propagated via the APIs exposed by this library, which originates in the user's code.
Variants
The most generic and possibly useless type of error, to be raised when no other information is available.
Code(i32)
The Code variant allows to encode errors as simple signed integers.
Message(String)
The Message variant allows to encode the error as a string.
The Any variant allows to encode any type of error with performance costs due to the heap allocations, and type erasure.
Example
use std::fmt; #[derive(Debug)] enum MyError { Audio, Game, InvalidArg { err: String } } impl fmt::Display for MyError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } } impl std::error::Error for MyError {} impl semeion::error::Any for MyError { fn as_any(&self) -> &dyn std::any::Any { self } } // we can get a `semeion::Error` from any of the public APIs let err = semeion::Error::with_err(MyError::Audio); // and downcast it back to its original concrete type with if let semeion::Error::Any(err) = err { let my_err = err.as_any().downcast_ref::<MyError>().unwrap(); }
Implementations
impl Error
[src]
pub fn with_message(message: impl Display) -> Self
[src]
Constructs a new Error with the given message.
pub fn with_err(err: impl Any + Send + 'static) -> Self
[src]
Constructs a new Error with the given custom value.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Error
impl Send for Error
impl !Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,