Skip to content

Commit

Permalink
Add a helper method for partial comparing unicode reaction emojis (#1103
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Th3-M4jor authored and arqunis committed Dec 4, 2020
1 parent ce66f8e commit 46c74e9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/model/channel/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
Result as FmtResult,
Write as FmtWrite
},
cmp::Ordering
};

use crate::internal::prelude::*;
Expand Down Expand Up @@ -378,9 +379,9 @@ impl ReactionType {
}
}

/// Helper function to allow comparing unicode emojis without having to
/// perform any allocation. Will always return false if the reaction was
/// not a unicode reaction.
/// Helper function to allow testing equality of unicode emojis without
/// having to perform any allocation.
/// Will always return false if the reaction was not a unicode reaction.
pub fn unicode_eq(&self, other: &str) -> bool {

if let ReactionType::Unicode(unicode) = &self {
Expand All @@ -391,6 +392,20 @@ impl ReactionType {
}

}

/// Helper function to allow comparing unicode emojis without having
/// to perform any allocation.
/// Will return None if the reaction was not a unicode reaction.
pub fn unicode_partial_cmp(&self, other: &str) -> Option<Ordering> {

if let ReactionType::Unicode(unicode) = &self {
Some(unicode.as_str().cmp(other))
} else {
// Always return None if not a unicode reaction
None
}

}
}

impl From<char> for ReactionType {
Expand Down

0 comments on commit 46c74e9

Please sign in to comment.