Skip to content

Commit

Permalink
add function to iterate over all shortcodes
Browse files Browse the repository at this point in the history
Also return clonable iterators.
  • Loading branch information
boxdot committed Mar 5, 2024
1 parent b088b12 commit 9dbd425
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,25 @@ impl Group {
/// assert_eq!(faces, ["😀", "😃", "😄", "😁", "😆"]);
/// ```
#[inline]
pub fn iter() -> impl Iterator<Item = &'static Emoji> {
pub fn iter() -> impl Iterator<Item = &'static Emoji> + Clone {
crate::gen::EMOJIS
.iter()
.filter(|emoji| matches!(emoji.skin_tone(), Some(SkinTone::Default) | None))
}

/// Returns an iterator over all shortcodes.
///
/// # Examples
///
/// ```
/// let shortcodes: Vec<_> = emojis::shortcodes().take(3).collect();
/// assert_eq!(shortcodes, ["algeria", "pouting_face", "waning_crescent_moon"]);
/// ```
#[inline]
pub fn shortcodes() -> impl Iterator<Item = &'static str> + Clone {
crate::gen::shortcode::MAP.keys().into_iter().copied()
}

/// Lookup an emoji by Unicode value.
///
/// This take *Ο(1)* time.
Expand Down

0 comments on commit 9dbd425

Please sign in to comment.