Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swarm): add ConnectionDenied::downcast_ref #4020

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@

- Remove deprecated items. See [PR 3956].

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

[PR 3292]: https://github.com/libp2p/rust-libp2p/pull/3292
[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605
[PR 3651]: https://github.com/libp2p/rust-libp2p/pull/3651
Expand All @@ -80,6 +82,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
[PR 4037]: https://github.com/libp2p/rust-libp2p/pull/4037

## 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 @@ -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 {
Expand Down