Skip to content

Commit

Permalink
feat(swarm): add ConnectionDenied::downcast_ref
Browse files Browse the repository at this point in the history
Prior to this change it was possible to only have a reference to a ConnectionDenied error and not be
able to downcast it to check if the connection-limits produced the error.
  • Loading branch information
nathanielc committed Jun 12, 2023
1 parent b73f720 commit f7837e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@

- Remove deprecated items. See [PR 3956].

- Add ability to `downcast_ref` ConnectionDenied errors. See [PR 4020].

[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605
[PR 3651]: https://github.com/libp2p/rust-libp2p/pull/3651
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
Expand All @@ -73,6 +75,7 @@
[PR 3927]: https://github.com/libp2p/rust-libp2p/pull/3927
[PR 3955]: https://github.com/libp2p/rust-libp2p/pull/3955
[PR 3956]: https://github.com/libp2p/rust-libp2p/pull/3956
[PR 4020]: https://github.com/libp2p/rust-libp2p/pull/4020

## 0.42.2

Expand Down
8 changes: 8 additions & 0 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,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 {
Expand Down

0 comments on commit f7837e7

Please sign in to comment.