mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-14 02:21:21 +00:00
swarm/behaviour: Replace inject_*
with on_event
(#3011)
This commit is contained in:
@ -29,6 +29,8 @@ use libp2p_core::upgrade::{EitherUpgrade, UpgradeError};
|
||||
use libp2p_core::{ConnectedPoint, Multiaddr, PeerId};
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
/// Auxiliary type to allow implementing [`IntoConnectionHandler`]. As [`IntoConnectionHandler`] is
|
||||
/// already implemented for T, we cannot implement it for Either<A, B>.
|
||||
pub enum IntoEitherHandler<L, R> {
|
||||
Left(L),
|
||||
Right(R),
|
||||
@ -64,6 +66,29 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// Taken from https://github.com/bluss/either.
|
||||
impl<L, R> IntoEitherHandler<L, R> {
|
||||
/// Returns the left value.
|
||||
pub fn unwrap_left(self) -> L {
|
||||
match self {
|
||||
IntoEitherHandler::Left(l) => l,
|
||||
IntoEitherHandler::Right(_) => {
|
||||
panic!("called `IntoEitherHandler::unwrap_left()` on a `Right` value.",)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the right value.
|
||||
pub fn unwrap_right(self) -> R {
|
||||
match self {
|
||||
IntoEitherHandler::Right(r) => r,
|
||||
IntoEitherHandler::Left(_) => {
|
||||
panic!("called `IntoEitherHandler::unwrap_right()` on a `Left` value.",)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of a [`ConnectionHandler`] that represents either of two [`ConnectionHandler`]
|
||||
/// implementations.
|
||||
impl<L, R> ConnectionHandler for Either<L, R>
|
||||
|
Reference in New Issue
Block a user