chore: Inline small functions

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-07-01 15:20:30 +00:00
parent 7e479f3c7a
commit 9e1e5d7c42
4 changed files with 30 additions and 0 deletions

View File

@@ -66,6 +66,7 @@ pub enum IssueStatus {
impl IssueStatus { impl IssueStatus {
/// Maps the issue status to its corresponding Nostr kind. /// Maps the issue status to its corresponding Nostr kind.
#[inline]
pub fn kind(&self) -> Kind { pub fn kind(&self) -> Kind {
match self { match self {
Self::Open => Kind::GitStatusOpen, Self::Open => Kind::GitStatusOpen,
@@ -75,16 +76,19 @@ impl IssueStatus {
} }
/// Check if the issue is open. /// Check if the issue is open.
#[inline]
pub fn is_open(&self) -> bool { pub fn is_open(&self) -> bool {
matches!(self, Self::Open) matches!(self, Self::Open)
} }
/// Check if the issue is resolved. /// Check if the issue is resolved.
#[inline]
pub fn is_resolved(&self) -> bool { pub fn is_resolved(&self) -> bool {
matches!(self, Self::Resolved) matches!(self, Self::Resolved)
} }
/// Check if the issue is closed. /// Check if the issue is closed.
#[inline]
pub fn is_closed(&self) -> bool { pub fn is_closed(&self) -> bool {
matches!(self, Self::Closed) matches!(self, Self::Closed)
} }

View File

@@ -105,6 +105,7 @@ pub enum PatchStatus {
impl PatchStatus { impl PatchStatus {
/// Maps the issue status to its corresponding Nostr kind. /// Maps the issue status to its corresponding Nostr kind.
#[inline]
pub fn kind(&self) -> Kind { pub fn kind(&self) -> Kind {
match self { match self {
Self::Open => Kind::GitStatusOpen, Self::Open => Kind::GitStatusOpen,
@@ -115,21 +116,25 @@ impl PatchStatus {
} }
/// Check if the patch is open. /// Check if the patch is open.
#[inline]
pub fn is_open(&self) -> bool { pub fn is_open(&self) -> bool {
matches!(self, Self::Open) matches!(self, Self::Open)
} }
/// Check if the patch is merged/applied. /// Check if the patch is merged/applied.
#[inline]
pub fn is_merged_or_applied(&self) -> bool { pub fn is_merged_or_applied(&self) -> bool {
matches!(self, Self::MergedApplied) matches!(self, Self::MergedApplied)
} }
/// Check if the patch is closed. /// Check if the patch is closed.
#[inline]
pub fn is_closed(&self) -> bool { pub fn is_closed(&self) -> bool {
matches!(self, Self::Closed) matches!(self, Self::Closed)
} }
/// Check if the patch is drafted /// Check if the patch is drafted
#[inline]
pub fn is_drafted(&self) -> bool { pub fn is_drafted(&self) -> bool {
matches!(self, Self::Draft) matches!(self, Self::Draft)
} }

View File

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

View File

@@ -43,17 +43,20 @@ use crate::{
}; };
/// Returns the value of the given tag /// Returns the value of the given tag
#[inline]
fn tag_value(tag: &TagStandard) -> String { fn tag_value(tag: &TagStandard) -> String {
tag.clone().to_vec().remove(1) tag.clone().to_vec().remove(1)
} }
/// Parses the tag value into type `T` if possible. /// Parses the tag value into type `T` if possible.
#[inline]
fn parse_value<T: FromStr>(tag: &TagStandard) -> Option<T> { fn parse_value<T: FromStr>(tag: &TagStandard) -> Option<T> {
tag_value(tag).parse().ok() tag_value(tag).parse().ok()
} }
/// Gets all values from the tag. If any value fails to parse, returns an empty /// Gets all values from the tag. If any value fails to parse, returns an empty
/// vector. /// vector.
#[inline]
fn tag_values<T>(tag: &TagStandard) -> Vec<T> fn tag_values<T>(tag: &TagStandard) -> Vec<T>
where where
T: FromStr + fmt::Debug, T: FromStr + fmt::Debug,
@@ -113,6 +116,7 @@ where
/// Creates a new NIP-19 nevent string from an event ID and up to 3 unique relay /// Creates a new NIP-19 nevent string from an event ID and up to 3 unique relay
/// URLs. /// URLs.
#[inline]
pub fn new_nevent(event_id: EventId, relays: &[RelayUrl]) -> N34Result<String> { pub fn new_nevent(event_id: EventId, relays: &[RelayUrl]) -> N34Result<String> {
Nip19Event::new(event_id) Nip19Event::new(event_id)
.relays( .relays(
@@ -127,6 +131,7 @@ pub fn new_nevent(event_id: EventId, relays: &[RelayUrl]) -> N34Result<String> {
/// Creates a NIP-19 naddr string for a git repository announcement and up to 3 /// Creates a NIP-19 naddr string for a git repository announcement and up to 3
/// unique relay URLs. /// unique relay URLs.
#[inline]
pub fn repo_naddr( pub fn repo_naddr(
repo_id: impl Into<String>, repo_id: impl Into<String>,
pubk: PublicKey, pubk: PublicKey,
@@ -223,6 +228,7 @@ pub fn get_content(
} }
/// Path to the `nostr-address` file in current directory. /// Path to the `nostr-address` file in current directory.
#[inline]
pub fn nostr_address_path() -> std::io::Result<PathBuf> { pub fn nostr_address_path() -> std::io::Result<PathBuf> {
std::env::current_dir().map(|p| p.join(NOSTR_ADDRESS_FILE)) std::env::current_dir().map(|p| p.join(NOSTR_ADDRESS_FILE))
} }
@@ -247,6 +253,7 @@ pub fn naddrs_or_file(
/// Generate a reply tag for an event with the given ID, relay URL (if any), and /// Generate a reply tag for an event with the given ID, relay URL (if any), and
/// marker. /// marker.
#[inline]
pub fn event_reply_tag(reply_to: &EventId, relay: Option<&RelayUrl>, marker: Marker) -> Tag { pub fn event_reply_tag(reply_to: &EventId, relay: Option<&RelayUrl>, marker: Marker) -> Tag {
Tag::custom( Tag::custom(
TagKind::e(), TagKind::e(),