@@ -37,12 +37,14 @@ use crate::error::{N34Error, N34Result};
|
||||
#[easy_ext::ext(TagsExt)]
|
||||
impl Tags {
|
||||
/// Search for the given tag and map it value to a function
|
||||
#[inline]
|
||||
pub fn map_tag<T>(&self, kind: TagKind, f: impl FnOnce(&TagStandard) -> T) -> Option<T> {
|
||||
self.find_standardized(kind).map(f)
|
||||
}
|
||||
|
||||
/// Search for the given tag and map it value to a function. If the tag not
|
||||
/// found return the default `T`
|
||||
#[inline]
|
||||
pub fn dmap_tag<T>(&self, kind: TagKind, f: impl FnOnce(&TagStandard) -> T) -> T
|
||||
where
|
||||
T: Default,
|
||||
@@ -52,6 +54,7 @@ impl Tags {
|
||||
|
||||
/// Finds the first standard tag of the given kind with the specified
|
||||
/// marker, then applies the function to the tag and returns the result.
|
||||
#[inline]
|
||||
pub fn map_marker<T>(
|
||||
&self,
|
||||
kind: TagKind,
|
||||
@@ -148,6 +151,7 @@ impl EventBuilder {
|
||||
impl Token<'_> {
|
||||
/// Returns `Some((public_key, relays))` from the givin token if it's npub1
|
||||
/// or nprofile1
|
||||
#[inline]
|
||||
pub fn extract_public_key(&self) -> Option<(PublicKey, Vec<RelayUrl>)> {
|
||||
match self {
|
||||
Token::Nostr(nip21) => {
|
||||
@@ -163,6 +167,7 @@ impl Token<'_> {
|
||||
|
||||
/// Returns `Some((note_id, relays))` from the givin token if it's note1 or
|
||||
/// nevent1
|
||||
#[inline]
|
||||
pub fn extract_event_id(&self) -> Option<(EventId, Vec<RelayUrl>)> {
|
||||
match self {
|
||||
Token::Nostr(nip21) => {
|
||||
@@ -177,6 +182,7 @@ impl Token<'_> {
|
||||
}
|
||||
|
||||
/// Returns `Some(hashtag)` from the givin token if it's a hashtag
|
||||
#[inline]
|
||||
pub fn extract_hashtag(&self) -> Option<String> {
|
||||
match self {
|
||||
Token::Hashtag(tag) => Some(tag.trim().to_owned()),
|
||||
@@ -189,16 +195,19 @@ impl Token<'_> {
|
||||
#[easy_ext::ext(NaddrsUtils)]
|
||||
impl Vec<Nip19Coordinate> {
|
||||
/// Converts these coordinate addresses to basic coordinates
|
||||
#[inline]
|
||||
pub fn into_coordinates(self) -> Vec<Coordinate> {
|
||||
self.into_iter().map(|n| n.coordinate).collect()
|
||||
}
|
||||
|
||||
/// Returns all repository owners' public keys from these coordinates.
|
||||
#[inline]
|
||||
pub fn extract_owners(&self) -> Vec<PublicKey> {
|
||||
self.iter().map(|n| n.public_key).collect()
|
||||
}
|
||||
|
||||
/// Extracts all relay URLs from these coordinates
|
||||
#[inline]
|
||||
pub fn extract_relays(&self) -> Vec<RelayUrl> {
|
||||
self.iter().flat_map(|n| n.relays.clone()).collect()
|
||||
}
|
||||
@@ -208,16 +217,19 @@ impl Vec<Nip19Coordinate> {
|
||||
#[easy_ext::ext(ReposUtils)]
|
||||
impl Vec<GitRepositoryAnnouncement> {
|
||||
/// Extracts all relay URLs from these repositories
|
||||
#[inline]
|
||||
pub fn extract_relays(&self) -> Vec<RelayUrl> {
|
||||
self.iter().flat_map(|n| n.relays.clone()).collect()
|
||||
}
|
||||
|
||||
/// Extract all the maintainers from these repositories
|
||||
#[inline]
|
||||
pub fn extract_maintainers(&self) -> Vec<PublicKey> {
|
||||
self.iter().flat_map(|r| r.maintainers.clone()).collect()
|
||||
}
|
||||
|
||||
/// Gets the first EUC hash from the reposotoies if it exists.
|
||||
#[inline]
|
||||
pub fn extract_euc(&self) -> Option<&Sha1Hash> {
|
||||
self.iter().find_map(|r| r.euc.as_ref())
|
||||
}
|
||||
@@ -227,6 +239,7 @@ impl Vec<GitRepositoryAnnouncement> {
|
||||
#[easy_ext::ext(GitPatchUtils)]
|
||||
impl Event {
|
||||
/// Returns whether the patch is a root or not
|
||||
#[inline]
|
||||
pub fn is_root_patch(&self) -> bool {
|
||||
self.kind == Kind::GitPatch
|
||||
&& self
|
||||
@@ -236,6 +249,7 @@ impl Event {
|
||||
}
|
||||
|
||||
/// Returns whether the patch is patch-revision or not
|
||||
#[inline]
|
||||
pub fn is_revision_patch(&self) -> bool {
|
||||
self.kind == Kind::GitPatch
|
||||
&& self
|
||||
|
||||
Reference in New Issue
Block a user