16
16
use futures:: Future ;
17
17
use serde_derive:: * ;
18
18
use std:: {
19
+ fmt,
19
20
ops:: {
20
21
Bound , Deref , DerefMut , Range , RangeFrom , RangeFull , RangeInclusive , RangeTo ,
21
22
RangeToInclusive ,
22
23
} ,
23
24
path:: PathBuf ,
25
+ str,
24
26
time:: Duration ,
25
27
u8:: { MAX as U8_MAX , MIN as U8_MIN } ,
26
28
} ;
@@ -35,6 +37,17 @@ pub use crate::errors::Error;
35
37
#[ doc( inline) ]
36
38
pub use crate :: errors:: Result ;
37
39
40
+ struct HexRepr < ' a > ( pub & ' a [ u8 ] ) ;
41
+
42
+ impl < ' a > fmt:: Display for HexRepr < ' a > {
43
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
44
+ for byte in self . 0 {
45
+ write ! ( f, "{:02X}" , byte) ?;
46
+ }
47
+ Ok ( ( ) )
48
+ }
49
+ }
50
+
38
51
/// The key part of a key/value pair.
39
52
///
40
53
/// In TiKV, keys are an ordered sequence of bytes. This has an advantage over choosing `String` as
@@ -72,7 +85,7 @@ pub use crate::errors::Result;
72
85
/// **But, you should not need to worry about all this:** Many functions which accept a `Key`
73
86
/// accept an `Into<Key>`, which means all of the above types can be passed directly to those
74
87
/// functions.
75
- #[ derive( Default , Clone , Eq , PartialEq , Ord , PartialOrd , Hash , Debug ) ]
88
+ #[ derive( Default , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
76
89
pub struct Key ( Vec < u8 > ) ;
77
90
78
91
impl Key {
@@ -142,6 +155,12 @@ impl DerefMut for Key {
142
155
}
143
156
}
144
157
158
+ impl fmt:: Debug for Key {
159
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
160
+ write ! ( f, "Key({})" , HexRepr ( & self . 0 ) )
161
+ }
162
+ }
163
+
145
164
/// The value part of a key/value pair.
146
165
///
147
166
/// In TiKV, values are an ordered sequence of bytes. This has an advantage over choosing `String`
@@ -179,7 +198,7 @@ impl DerefMut for Key {
179
198
/// **But, you should not need to worry about all this:** Many functions which accept a `Value`
180
199
/// accept an `Into<Value>`, which means all of the above types can be passed directly to those
181
200
/// functions.
182
- #[ derive( Default , Clone , Eq , PartialEq , Hash , Debug ) ]
201
+ #[ derive( Default , Clone , Eq , PartialEq , Hash ) ]
183
202
pub struct Value ( Vec < u8 > ) ;
184
203
185
204
impl Value {
@@ -222,6 +241,15 @@ impl Deref for Value {
222
241
}
223
242
}
224
243
244
+ impl fmt:: Debug for Value {
245
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
246
+ match str:: from_utf8 ( & self . 0 ) {
247
+ Ok ( s) => write ! ( f, "Value({:?})" , s) ,
248
+ Err ( _) => write ! ( f, "Value({})" , HexRepr ( & self . 0 ) ) ,
249
+ }
250
+ }
251
+ }
252
+
225
253
/// A key/value pair.
226
254
///
227
255
/// ```rust
@@ -235,7 +263,7 @@ impl Deref for Value {
235
263
///
236
264
/// Many functions which accept a `KvPair` accept an `Into<KvPair>`, which means all of the above
237
265
/// types (Like a `(Key, Value)`) can be passed directly to those functions.
238
- #[ derive( Default , Clone , Eq , PartialEq , Debug ) ]
266
+ #[ derive( Default , Clone , Eq , PartialEq ) ]
239
267
pub struct KvPair ( Key , Value ) ;
240
268
241
269
impl KvPair {
@@ -307,6 +335,16 @@ where
307
335
}
308
336
}
309
337
338
+ impl fmt:: Debug for KvPair {
339
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
340
+ let KvPair ( key, value) = self ;
341
+ match str:: from_utf8 ( & value) {
342
+ Ok ( s) => write ! ( f, "KvPair({}, {:?})" , HexRepr ( & key) , s) ,
343
+ Err ( _) => write ! ( f, "KvPair({}, {})" , HexRepr ( & key) , HexRepr ( & value) ) ,
344
+ }
345
+ }
346
+ }
347
+
310
348
/// The configuration for either a [`raw::Client`](raw/struct.Client.html) or a
311
349
/// [`transaction::Client`](transaction/struct.Client.html).
312
350
///
0 commit comments