Skip to content

Commit c0a2acb

Browse files
committed
nostr: refactor NIP-17 relay list extraction functions to use impl Iterator
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 6824c73 commit c0a2acb

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

crates/nostr/src/nips/nip17.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,26 @@
66
//!
77
//! <https://github.com/nostr-protocol/nips/blob/master/17.md>
88
9-
use alloc::boxed::Box;
10-
use core::iter;
11-
12-
use crate::{Event, Kind, RelayUrl, TagStandard};
9+
use crate::{Event, RelayUrl, TagStandard};
1310

1411
/// Extracts the relay list
15-
pub fn extract_relay_list<'a>(event: &'a Event) -> Box<dyn Iterator<Item = &'a RelayUrl> + 'a> {
16-
if event.kind != Kind::InboxRelays {
17-
return Box::new(iter::empty());
18-
}
19-
20-
Box::new(event.tags.iter().filter_map(|tag| {
12+
pub fn extract_relay_list(event: &Event) -> impl Iterator<Item = &RelayUrl> {
13+
event.tags.iter().filter_map(|tag| {
2114
if let Some(TagStandard::Relay(url)) = tag.as_standardized() {
2215
Some(url)
2316
} else {
2417
None
2518
}
26-
}))
19+
})
2720
}
2821

2922
/// Extracts the relay list
30-
pub fn extract_owned_relay_list(event: Event) -> Box<dyn Iterator<Item = RelayUrl>> {
31-
if event.kind != Kind::InboxRelays {
32-
return Box::new(iter::empty());
33-
}
34-
35-
Box::new(event.tags.into_iter().filter_map(|tag| {
23+
pub fn extract_owned_relay_list(event: Event) -> impl Iterator<Item = RelayUrl> {
24+
event.tags.into_iter().filter_map(|tag| {
3625
if let Some(TagStandard::Relay(url)) = tag.to_standardized() {
3726
Some(url)
3827
} else {
3928
None
4029
}
41-
}))
30+
})
4231
}

0 commit comments

Comments
 (0)