@@ -66,7 +66,7 @@ impl<'de> Value<'de> {
66
66
pub fn has_key ( & self , key : & str ) -> bool {
67
67
self . value . as_ref ( ) . map_or ( false , |val| {
68
68
if let ValueInner :: Table ( table) = val {
69
- table. contains_key ( & key. into ( ) )
69
+ table. contains_key ( key)
70
70
} else {
71
71
false
72
72
}
@@ -144,7 +144,7 @@ impl<'de> Value<'de> {
144
144
/// Note that this is JSON pointer**-like** because `/` is not supported in
145
145
/// key names because I don't see the point. If you want this it is easy to
146
146
/// implement.
147
- pub fn pointer ( & self , pointer : & ' de str ) -> Option < & Self > {
147
+ pub fn pointer ( & self , pointer : & str ) -> Option < & Self > {
148
148
if pointer. is_empty ( ) {
149
149
return Some ( self ) ;
150
150
} else if !pointer. starts_with ( '/' ) {
@@ -157,9 +157,9 @@ impl<'de> Value<'de> {
157
157
// Don't support / or ~ in key names unless someone actually opens
158
158
// an issue about it
159
159
//.map(|x| x.replace("~1", "/").replace("~0", "~"))
160
- . try_fold ( self , |target, token| {
160
+ . try_fold ( self , move |target, token| {
161
161
( match & target. value {
162
- Some ( ValueInner :: Table ( tab) ) => tab. get ( & token. into ( ) ) ,
162
+ Some ( ValueInner :: Table ( tab) ) => tab. get ( token) ,
163
163
Some ( ValueInner :: Array ( list) ) => parse_index ( token) . and_then ( |x| list. get ( x) ) ,
164
164
_ => None ,
165
165
} )
@@ -183,7 +183,7 @@ impl<'de> Value<'de> {
183
183
//.map(|x| x.replace("~1", "/").replace("~0", "~"))
184
184
. try_fold ( self , |target, token| {
185
185
( match & mut target. value {
186
- Some ( ValueInner :: Table ( tab) ) => tab. get_mut ( & token. into ( ) ) ,
186
+ Some ( ValueInner :: Table ( tab) ) => tab. get_mut ( token) ,
187
187
Some ( ValueInner :: Array ( list) ) => {
188
188
parse_index ( token) . and_then ( |x| list. get_mut ( x) )
189
189
}
@@ -225,18 +225,21 @@ pub struct Key<'de> {
225
225
pub span : Span ,
226
226
}
227
227
228
- impl < ' de > From < & ' de str > for Key < ' de > {
229
- fn from ( k : & ' de str ) -> Self {
230
- Self {
231
- name : Cow :: Borrowed ( k) ,
232
- span : Span :: default ( ) ,
233
- }
228
+ impl < ' de > std:: borrow:: Borrow < str > for Key < ' de > {
229
+ fn borrow ( & self ) -> & str {
230
+ self . name . as_ref ( )
234
231
}
235
232
}
236
233
237
234
impl < ' de > fmt:: Debug for Key < ' de > {
238
235
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
239
- write ! ( f, "{}" , self . name)
236
+ f. write_str ( & self . name )
237
+ }
238
+ }
239
+
240
+ impl < ' de > fmt:: Display for Key < ' de > {
241
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
242
+ f. write_str ( & self . name )
240
243
}
241
244
}
242
245
0 commit comments