feat(mdns): change mdns::Event to hold Vec

In previous PR #3606 we've made `mdns::Event` `Clone`, but cloning single-use iterators doesn't sound right. Also you have to create an iterator from the actual data returned before putting it into events. So in this PR the iterators are replaced by `Vec`, as it's the type the data originally come from.



Related #3612.

Pull-Request: #3621.
This commit is contained in:
DrHuangMHT
2023-05-02 19:13:41 +08:00
committed by GitHub
parent 996b5c8bd0
commit 02d87155a5
4 changed files with 29 additions and 84 deletions

View File

@ -61,13 +61,13 @@ async fn test_expired_async_std() {
loop {
match futures::future::select(a.next_behaviour_event(), b.next_behaviour_event()).await {
Either::Left((Event::Expired(mut peers), _)) => {
if peers.any(|(p, _)| p == b_peer_id) {
Either::Left((Event::Expired(peers), _)) => {
if peers.into_iter().any(|(p, _)| p == b_peer_id) {
return;
}
}
Either::Right((Event::Expired(mut peers), _)) => {
if peers.any(|(p, _)| p == a_peer_id) {
Either::Right((Event::Expired(peers), _)) => {
if peers.into_iter().any(|(p, _)| p == a_peer_id) {
return;
}
}
@ -93,8 +93,8 @@ async fn test_no_expiration_on_close_async_std() {
// 1. Connect via address from mDNS event
loop {
if let Event::Discovered(mut peers) = a.next_behaviour_event().await {
if let Some((_, addr)) = peers.find(|(p, _)| p == &b_peer_id) {
if let Event::Discovered(peers) = a.next_behaviour_event().await {
if let Some((_, addr)) = peers.into_iter().find(|(p, _)| p == &b_peer_id) {
a.dial_and_wait(addr).await;
break;
}
@ -130,13 +130,13 @@ async fn run_discovery_test(config: Config) {
while !discovered_a && !discovered_b {
match futures::future::select(a.next_behaviour_event(), b.next_behaviour_event()).await {
Either::Left((Event::Discovered(mut peers), _)) => {
if peers.any(|(p, _)| p == b_peer_id) {
Either::Left((Event::Discovered(peers), _)) => {
if peers.into_iter().any(|(p, _)| p == b_peer_id) {
discovered_b = true;
}
}
Either::Right((Event::Discovered(mut peers), _)) => {
if peers.any(|(p, _)| p == a_peer_id) {
Either::Right((Event::Discovered(peers), _)) => {
if peers.into_iter().any(|(p, _)| p == a_peer_id) {
discovered_a = true;
}
}