mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
Implement Error for a few error types (#511)
This commit is contained in:
parent
4153cc4076
commit
6b1e4ab0a3
@ -1,5 +1,6 @@
|
|||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[cfg(feature = "unstable-futures")]
|
#[cfg(feature = "unstable-futures")]
|
||||||
@ -27,11 +28,23 @@ pub struct EnterError {
|
|||||||
impl fmt::Debug for EnterError {
|
impl fmt::Debug for EnterError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.debug_struct("EnterError")
|
f.debug_struct("EnterError")
|
||||||
.field("reason", &"attempted to run an executor while another executor is already running")
|
.field("reason", &self.description())
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for EnterError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(fmt, "{}", self.description())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for EnterError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"attempted to run an executor while another executor is already running"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Marks the current thread as being within the dynamic extent of an
|
/// Marks the current thread as being within the dynamic extent of an
|
||||||
/// executor.
|
/// executor.
|
||||||
///
|
///
|
||||||
|
@ -52,6 +52,9 @@ pub use global::spawn2;
|
|||||||
|
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
/// A value that executes futures.
|
/// A value that executes futures.
|
||||||
///
|
///
|
||||||
/// The [`spawn`] function is used to submit a future to an executor. Once
|
/// The [`spawn`] function is used to submit a future to an executor. Once
|
||||||
@ -238,3 +241,15 @@ impl SpawnError {
|
|||||||
!self.is_shutdown
|
!self.is_shutdown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for SpawnError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(fmt, "{}", self.description())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for SpawnError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"attempted to spawn task while the executor is at capacity or shut down"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -61,6 +61,7 @@ use tokio_executor::Enter;
|
|||||||
use tokio_executor::park::{Park, Unpark};
|
use tokio_executor::park::{Park, Unpark};
|
||||||
|
|
||||||
use std::{fmt, usize};
|
use std::{fmt, usize};
|
||||||
|
use std::error::Error;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
@ -771,3 +772,17 @@ fn lower_async<T>(new: futures2::Async<T>) -> futures::Async<T> {
|
|||||||
futures2::Async::Pending => futures::Async::NotReady,
|
futures2::Async::Pending => futures::Async::NotReady,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== impl SetFallbackError =====
|
||||||
|
|
||||||
|
impl fmt::Display for SetFallbackError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(fmt, "{}", self.description())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for SetFallbackError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"attempted to set fallback reactor while already configured"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -29,8 +29,8 @@ pub struct BlockingError {
|
|||||||
///
|
///
|
||||||
/// # Return
|
/// # Return
|
||||||
///
|
///
|
||||||
/// When the blocking closure is executed, `Ok(T)` is returned, where `T` is the
|
/// When the blocking closure is executed, `Ok(Ready(T))` is returned, where
|
||||||
/// closure's return value.
|
/// `T` is the closure's return value.
|
||||||
///
|
///
|
||||||
/// If the thread pool has shutdown, `Err` is returned.
|
/// If the thread pool has shutdown, `Err` is returned.
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user