@@ -2193,6 +2193,46 @@ fn test_borrowed_raw_value() {
2193
2193
assert_eq ! ( r#"["a",42,{"foo": "bar"},null]"# , array_to_string) ;
2194
2194
}
2195
2195
2196
+ #[ cfg( feature = "raw_value" ) ]
2197
+ #[ test]
2198
+ fn test_raw_value_in_map_key ( ) {
2199
+ use ref_cast:: RefCast ;
2200
+
2201
+ #[ derive( RefCast ) ]
2202
+ #[ repr( transparent) ]
2203
+ struct RawMapKey ( RawValue ) ;
2204
+
2205
+ impl < ' de > Deserialize < ' de > for & ' de RawMapKey {
2206
+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
2207
+ where
2208
+ D : serde:: Deserializer < ' de > ,
2209
+ {
2210
+ let raw_value = <& RawValue >:: deserialize ( deserializer) ?;
2211
+ Ok ( RawMapKey :: ref_cast ( raw_value) )
2212
+ }
2213
+ }
2214
+
2215
+ impl PartialEq for RawMapKey {
2216
+ fn eq ( & self , other : & Self ) -> bool {
2217
+ self . 0 . get ( ) == other. 0 . get ( )
2218
+ }
2219
+ }
2220
+
2221
+ impl Eq for RawMapKey { }
2222
+
2223
+ impl Hash for RawMapKey {
2224
+ fn hash < H : Hasher > ( & self , hasher : & mut H ) {
2225
+ self . 0 . get ( ) . hash ( hasher) ;
2226
+ }
2227
+ }
2228
+
2229
+ let map_from_str: std:: collections:: HashMap < & RawMapKey , & RawValue > =
2230
+ serde_json:: from_str ( r#" {"\\k":"\\v"} "# ) . unwrap ( ) ;
2231
+ let ( map_k, map_v) = map_from_str. into_iter ( ) . next ( ) . unwrap ( ) ;
2232
+ assert_eq ! ( "\" \\ \\ k\" " , map_k. 0 . get( ) ) ;
2233
+ assert_eq ! ( "\" \\ \\ v\" " , map_v. get( ) ) ;
2234
+ }
2235
+
2196
2236
#[ cfg( feature = "raw_value" ) ]
2197
2237
#[ test]
2198
2238
fn test_boxed_raw_value ( ) {
0 commit comments