Skip to content

Commit

Permalink
feat(iroh): implement Discovery for Arc'ed Discovery types (#3107)
Browse files Browse the repository at this point in the history
## Description

Nothing in the trait stops it from working for discovery structs which
are Arc'ed.  Not all discovery types are in control of the users so
this is helpful.

I stumbled upon this because StaticProvider is not Clone.

## Breaking Changes

<!-- Optional, if there are any breaking changes document them,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All breaking changes documented.
  • Loading branch information
flub authored Jan 13, 2025
1 parent 3891778 commit f675525
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion iroh/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
doc = "[`LocalSwarmDiscovery`]: local_swarm_discovery::LocalSwarmDiscovery"
)]

use std::{collections::BTreeSet, net::SocketAddr, time::Duration};
use std::{collections::BTreeSet, net::SocketAddr, sync::Arc, time::Duration};

use anyhow::{anyhow, ensure, Result};
use futures_lite::stream::{Boxed as BoxStream, StreamExt};
Expand Down Expand Up @@ -194,6 +194,8 @@ pub trait Discovery: std::fmt::Debug + Send + Sync {
}
}

impl<T: Discovery> Discovery for Arc<T> {}

/// The results returned from [`Discovery::resolve`].
#[derive(Debug, Clone)]
pub struct DiscoveryItem {
Expand Down

0 comments on commit f675525

Please sign in to comment.