Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Replace RelayMap::extend() member fn with RelayMap::join
Signed-off-by: Matthias Beyer <[email protected]>
  • Loading branch information
matthiasbeyer committed Oct 31, 2025
commit 6edd6dc243113231424f15349196e49f38e93a18
13 changes: 8 additions & 5 deletions iroh-relay/src/relay_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ impl RelayMap {
self.relays.write().expect("poisoned").remove(url)
}

/// Extends this `RelayMap` with another one.
pub fn extend(&self, other: &RelayMap) {
let mut a = self.relays.write().expect("poisoned");
let b = other.relays.read().expect("poisoned");
a.extend(b.iter().map(|(a, b)| (a.clone(), b.clone())));
/// Joins this `RelayMap` with another one into a new one
pub fn join(self, other: RelayMap) -> RelayMap {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this called chain usually? I think this is very similar to the Iterator::chain signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is. I opted for join because a Map is not something that can (semantically) be put into a ⛓️ chain! 😉 I think of chain() something that can be applied to a sequence of something (hence Iterator::chain but not BTreeMap::chain for example).

I have no strong feelings about the actual method name tho, so if you want me to change it, I'll happily do so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not convinced passing owned versions makes sense for a fully clonable thing. This API really doesn't communicate the fact that this doesn't actually create a new version, but rather modifies the underlying, likely shared instances

{
let mut a = self.relays.write().expect("poisoned");
let b = other.relays.read().expect("poisoned");
a.extend(b.iter().map(|(a, b)| (a.clone(), b.clone())));
}
self
}
}

Expand Down
Loading