mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
parent
46149f031e
commit
676824988e
@ -32,6 +32,8 @@ pub struct Receiver<T> {
|
|||||||
pub mod error {
|
pub mod error {
|
||||||
//! Oneshot error types
|
//! Oneshot error types
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
/// Error returned by the `Future` implementation for `Receiver`.
|
/// Error returned by the `Future` implementation for `Receiver`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RecvError(pub(super) ());
|
pub struct RecvError(pub(super) ());
|
||||||
@ -39,6 +41,36 @@ pub mod error {
|
|||||||
/// Error returned by the `try_recv` function on `Receiver`.
|
/// Error returned by the `try_recv` function on `Receiver`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TryRecvError(pub(super) ());
|
pub struct TryRecvError(pub(super) ());
|
||||||
|
|
||||||
|
// ===== impl RecvError =====
|
||||||
|
|
||||||
|
impl fmt::Display for RecvError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use std::error::Error;
|
||||||
|
write!(fmt, "{}", self.description())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ::std::error::Error for RecvError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"channel closed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== impl TryRecvError =====
|
||||||
|
|
||||||
|
impl fmt::Display for TryRecvError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use std::error::Error;
|
||||||
|
write!(fmt, "{}", self.description())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ::std::error::Error for TryRecvError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"channel closed"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use self::error::*;
|
use self::error::*;
|
||||||
|
@ -104,6 +104,8 @@ pub struct Ref<'a, T: 'a> {
|
|||||||
pub mod error {
|
pub mod error {
|
||||||
//! Watch error types
|
//! Watch error types
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
/// Error produced when receiving a value fails.
|
/// Error produced when receiving a value fails.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RecvError {
|
pub struct RecvError {
|
||||||
@ -115,6 +117,36 @@ pub mod error {
|
|||||||
pub struct SendError<T> {
|
pub struct SendError<T> {
|
||||||
pub(crate) inner: T,
|
pub(crate) inner: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== impl RecvError =====
|
||||||
|
|
||||||
|
impl fmt::Display for RecvError {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use std::error::Error;
|
||||||
|
write!(fmt, "{}", self.description())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ::std::error::Error for RecvError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"channel closed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== impl SendError =====
|
||||||
|
|
||||||
|
impl<T: fmt::Debug> fmt::Display for SendError<T> {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use std::error::Error;
|
||||||
|
write!(fmt, "{}", self.description())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: fmt::Debug> ::std::error::Error for SendError<T> {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"channel closed"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
extern crate tokio_sync;
|
extern crate tokio_sync;
|
||||||
|
|
||||||
use tokio_sync::mpsc::error;
|
|
||||||
|
|
||||||
fn is_error<T: ::std::error::Error + Send + Sync>() {}
|
fn is_error<T: ::std::error::Error + Send + Sync>() {}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_bound() {
|
fn mpsc_error_bound() {
|
||||||
|
use tokio_sync::mpsc::error;
|
||||||
|
|
||||||
is_error::<error::RecvError>();
|
is_error::<error::RecvError>();
|
||||||
is_error::<error::SendError>();
|
is_error::<error::SendError>();
|
||||||
is_error::<error::TrySendError<()>>();
|
is_error::<error::TrySendError<()>>();
|
||||||
@ -15,3 +15,19 @@ fn error_bound() {
|
|||||||
is_error::<error::UnboundedSendError>();
|
is_error::<error::UnboundedSendError>();
|
||||||
is_error::<error::UnboundedTrySendError<()>>();
|
is_error::<error::UnboundedTrySendError<()>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn oneshot_error_bound() {
|
||||||
|
use tokio_sync::oneshot::error;
|
||||||
|
|
||||||
|
is_error::<error::RecvError>();
|
||||||
|
is_error::<error::TryRecvError>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn watch_error_bound() {
|
||||||
|
use tokio_sync::watch::error;
|
||||||
|
|
||||||
|
is_error::<error::RecvError>();
|
||||||
|
is_error::<error::SendError<()>>();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user