File tree Expand file tree Collapse file tree 3 files changed +52
-5
lines changed
Expand file tree Collapse file tree 3 files changed +52
-5
lines changed Original file line number Diff line number Diff line change 11# 📝 Release notes
22
3+ ## 0.7.2
4+
5+ * Unreleased*
6+
7+ - [ Implement ` PartialOrd ` and ` Ord ` for ` Emoji ` ] [ todo ] . This allows emojis to
8+ be compared and sorted. The order is based on the Unicode code point order.
9+
310## 0.7.1
411
512* July 31st, 2025*
Original file line number Diff line number Diff line change @@ -459,26 +459,43 @@ impl Emoji {
459459impl cmp:: PartialEq < Emoji > for Emoji {
460460 #[ inline]
461461 fn eq ( & self , other : & Emoji ) -> bool {
462- self . emoji == other. emoji
462+ self . emoji . eq ( other. emoji )
463463 }
464464}
465465
466466impl cmp:: PartialEq < str > for Emoji {
467467 #[ inline]
468468 fn eq ( & self , s : & str ) -> bool {
469- self . as_str ( ) == s
469+ self . emoji . eq ( s )
470470 }
471471}
472472
473+ // TODO: needed?
473474impl cmp:: PartialEq < & str > for Emoji {
474475 #[ inline]
475476 fn eq ( & self , s : & & str ) -> bool {
476- self . as_str ( ) == * s
477+ self . emoji . eq ( * s )
477478 }
478479}
479480
480481impl cmp:: Eq for Emoji { }
481482
483+ impl cmp:: PartialOrd < Emoji > for Emoji {
484+ /// Compares two emojis based on their *Unicode* value.
485+ #[ inline]
486+ fn partial_cmp ( & self , other : & Emoji ) -> Option < cmp:: Ordering > {
487+ self . emoji . partial_cmp ( other. emoji )
488+ }
489+ }
490+
491+ impl cmp:: Ord for Emoji {
492+ /// Compares two emojis based on their *Unicode* value.
493+ #[ inline]
494+ fn cmp ( & self , other : & Emoji ) -> cmp:: Ordering {
495+ self . emoji . cmp ( other. emoji )
496+ }
497+ }
498+
482499impl hash:: Hash for Emoji {
483500 #[ inline]
484501 fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
Original file line number Diff line number Diff line change 1+ use core:: cmp:: Ordering ;
2+
13use emojis:: { SkinTone , UnicodeVersion } ;
24
35#[ test]
@@ -29,8 +31,29 @@ fn unicode_version_partial_ord() {
2931}
3032
3133#[ test]
32- fn emoji_partial_eq_str ( ) {
33- assert_eq ! ( emojis:: get( "😀" ) . unwrap( ) , "😀" ) ;
34+ fn emoji_eq ( ) {
35+ let a = emojis:: get ( "😀" ) . unwrap ( ) ;
36+ let b = emojis:: get ( "😃" ) . unwrap ( ) ;
37+ assert ! ( a != b) ;
38+ assert ! ( b != a) ;
39+ assert ! ( a == a) ;
40+ assert ! ( b == b) ;
41+ assert ! ( a != "😃" ) ;
42+ assert ! ( b == "😃" ) ;
43+ }
44+
45+ #[ test]
46+ fn emoji_ord ( ) {
47+ let a = emojis:: get ( "😀" ) . unwrap ( ) ;
48+ let b = emojis:: get ( "😃" ) . unwrap ( ) ;
49+ assert_eq ! ( a. partial_cmp( b) , Some ( Ordering :: Less ) ) ;
50+ assert_eq ! ( b. partial_cmp( a) , Some ( Ordering :: Greater ) ) ;
51+ assert_eq ! ( a. partial_cmp( a) , Some ( Ordering :: Equal ) ) ;
52+ assert_eq ! ( b. partial_cmp( b) , Some ( Ordering :: Equal ) ) ;
53+ assert_eq ! ( a. cmp( b) , Ordering :: Less ) ;
54+ assert_eq ! ( b. cmp( a) , Ordering :: Greater ) ;
55+ assert_eq ! ( a. cmp( a) , Ordering :: Equal ) ;
56+ assert_eq ! ( b. cmp( b) , Ordering :: Equal ) ;
3457}
3558
3659#[ test]
You can’t perform that action at this time.
0 commit comments