use crate::{ import::* };
#[ derive( Debug ) ]
pub struct Error
{
kind: ErrorKind,
}
impl StdError for Error {}
#[ derive( Copy, Clone, PartialEq, Eq, Debug ) ]
pub enum ErrorKind
{
DoubleExecutorInit,
Spawn,
Run,
SpawnLocalOnThreadPool,
WrongExecutor,
NoExecutorInitialized,
__Nonexhaustive,
}
impl fmt::Display for ErrorKind
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
match self
{
Self::DoubleExecutorInit => fmt::Display::fmt( "DoubleExecutorInit: Cannot initialize global executor twice.", f ) ,
Self::Spawn => fmt::Display::fmt( "Spawn: Failed to spawn a future.", f ) ,
Self::Run => fmt::Display::fmt( "Run: Failed to run an executor to completion.", f ) ,
Self::SpawnLocalOnThreadPool => fmt::Display::fmt( "Spawn: You can not spawn `!Send` futures on a thread pool. If your feature is `Send`, use `rt::spawn`, otherwise initialize this thread with a Local executor.", f ) ,
Self::WrongExecutor => fmt::Display::fmt( "You tried to use a functionality specific to a certain executor while another executor was being used for this thread.", f ) ,
Self::NoExecutorInitialized => fmt::Display::fmt( "You must initialize an executor on this thread before calls to spawn.", f ) ,
_ => unreachable!(),
}
}
}
impl fmt::Display for Error
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
write!( f, "async_runtime::Error: {}", &self.kind )
}
}
impl Error
{
pub fn new( kind: ErrorKind ) -> Self
{
Error { kind }
}
pub fn kind( &self ) -> &ErrorKind
{
&self.kind
}
}
impl From<ErrorKind> for Error
{
fn from( kind: ErrorKind ) -> Error
{
Error { kind }
}
}