mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-03 11:41:34 +00:00
feat(swarm): add ConnectionDenied::downcast_ref
Prior to this change it was only possible to downcast a `ConnectionDenied` error when you had ownership of it which isn't the case inside `NetworkBehaviour`s. This change allows downcasting by reference. See https://github.com/libp2p/rust-libp2p/discussions/4018. Pull-Request: #4020.
This commit is contained in:
@ -1730,6 +1730,14 @@ impl ConnectionDenied {
|
||||
|
||||
Ok(*inner)
|
||||
}
|
||||
|
||||
/// Attempt to downcast to a particular reason for why the connection was denied.
|
||||
pub fn downcast_ref<E>(&self) -> Option<&E>
|
||||
where
|
||||
E: error::Error + Send + Sync + 'static,
|
||||
{
|
||||
self.inner.downcast_ref::<E>()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ConnectionDenied {
|
||||
|
Reference in New Issue
Block a user