File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,13 @@ impl std::fmt::Debug for InlineStr {
3535 }
3636}
3737
38+ impl std:: hash:: Hash for InlineStr {
39+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
40+ let as_str: & str = & * self ;
41+ as_str. hash ( state) ;
42+ }
43+ }
44+
3845impl From < String > for InlineStr {
3946 fn from ( value : String ) -> Self {
4047 Self {
@@ -107,6 +114,8 @@ impl PartialEq<InlineStr> for Cow<'_, str> {
107114
108115#[ cfg( test) ]
109116mod tests {
117+ use std:: hash:: { BuildHasher , RandomState } ;
118+
110119 use super :: * ;
111120
112121 #[ test]
@@ -118,4 +127,19 @@ mod tests {
118127 assert_eq ! ( words, inline_words) ;
119128 assert_eq ! ( inline_words, words) ;
120129 }
130+
131+ #[ test]
132+ fn test_basic_hash ( ) {
133+ let hasher = RandomState :: new ( ) ;
134+
135+ let words = "the quick brown fox" ;
136+ let inline_words = InlineStr :: from ( words) ;
137+
138+ let words_hash = hasher. hash_one ( words) ;
139+ let words_hash_2 = hasher. hash_one ( words) ;
140+ let inline_hash = hasher. hash_one ( inline_words) ;
141+
142+ assert_eq ! ( words_hash, words_hash_2) ;
143+ assert_eq ! ( words_hash, inline_hash) ;
144+ }
121145}
You can’t perform that action at this time.
0 commit comments