mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
Split ConnectionUpgrade
. (#642)
Introduce `InboundUpgrade` and `OutboundUpgrade`.
This commit is contained in:
committed by
Pierre Krieger
parent
466385a58a
commit
2e549884ef
@ -18,11 +18,42 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
use crate::{muxing::{Shutdown, StreamMuxer}, Multiaddr};
|
||||
use futures::prelude::*;
|
||||
use muxing::{Shutdown, StreamMuxer};
|
||||
use std::io::{Error as IoError, Read, Write};
|
||||
use std::{fmt, io::{Error as IoError, Read, Write}};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use Multiaddr;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum EitherError<A, B> {
|
||||
A(A),
|
||||
B(B)
|
||||
}
|
||||
|
||||
impl<A, B> fmt::Display for EitherError<A, B>
|
||||
where
|
||||
A: fmt::Display,
|
||||
B: fmt::Display
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
EitherError::A(a) => a.fmt(f),
|
||||
EitherError::B(b) => b.fmt(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, B> std::error::Error for EitherError<A, B>
|
||||
where
|
||||
A: fmt::Debug + std::error::Error,
|
||||
B: fmt::Debug + std::error::Error
|
||||
{
|
||||
fn cause(&self) -> Option<&dyn std::error::Error> {
|
||||
match self {
|
||||
EitherError::A(a) => a.cause(),
|
||||
EitherError::B(b) => b.cause()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Implements `AsyncRead` and `AsyncWrite` and dispatches all method calls to
|
||||
/// either `First` or `Second`.
|
||||
|
Reference in New Issue
Block a user