Skip to content
This repository was archived by the owner on Oct 9, 2019. It is now read-only.

Commit 21746f6

Browse files
committed
add TakeError
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent 6014621 commit 21746f6

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait WriteReady {
4242
type Ok;
4343

4444
/// The type of failures yielded by this trait.
45-
type Err;
45+
type Err: std::error::Error + Send + Sync;
4646

4747
/// Check if the underlying API can be written to.
4848
fn poll_write_ready(&mut self, waker: &Waker) -> Poll<Result<Self::Ok, Self::Err>>;
@@ -54,7 +54,7 @@ pub trait ReadReady {
5454
type Ok;
5555

5656
/// The type of failures yielded by this trait.
57-
type Err;
57+
type Err: std::error::Error + Send + Sync;
5858

5959
/// Check if the underlying API can be read from.
6060
fn poll_read_ready(&mut self, waker: &Waker) -> Poll<Result<Self::Ok, Self::Err>>;
@@ -73,8 +73,27 @@ pub trait Ready {
7373
type Ok;
7474

7575
/// The type of failures yielded by this trait.
76-
type Err;
76+
type Err: std::error::Error + Send + Sync;
7777

7878
/// Check if the stream can be read from.
7979
fn poll_ready(&mut self, waker: &Waker) -> Poll<Result<Self::Ok, Self::Err>>;
8080
}
81+
82+
/// Extract an error from the underlying struct that isn't propagated through
83+
/// regular channels.
84+
///
85+
/// This is common in `TcpListener` / `UdsStream` structs where this trait can
86+
/// be used to access the `SO_ERROR` option on the socket.
87+
///
88+
/// Both `Ok` and `Err` are error types. If no error exists `take_error` should
89+
/// return `Ok(None)`.
90+
pub trait TakeError {
91+
/// The type of successful values yielded by this trait.
92+
type Ok: std::error::Error + Send + Sync;
93+
94+
/// The type of failures yielded by this trait.
95+
type Err: std::error::Error + Send + Sync;
96+
97+
/// Return an underlying error value of the struct.
98+
fn take_error(&self) -> Result<Option<Self::Ok>, Self::Err>;
99+
}

0 commit comments

Comments
 (0)