@@ -46,21 +46,6 @@ impl DocType {
46
46
pub fn doc_types ( & self ) -> & Vec < UuidV4 > {
47
47
& self . 0
48
48
}
49
-
50
- /// Convert `DocType` to coset `Value`.
51
- pub ( crate ) fn to_value ( & self ) -> Value {
52
- Value :: Array (
53
- self . 0
54
- . iter ( )
55
- . map ( |uuidv4| {
56
- Value :: Tag (
57
- UUID_CBOR_TAG ,
58
- Box :: new ( Value :: Bytes ( uuidv4. uuid ( ) . as_bytes ( ) . to_vec ( ) ) ) ,
59
- )
60
- } )
61
- . collect ( ) ,
62
- )
63
- }
64
49
}
65
50
66
51
impl Hash for DocType {
@@ -275,13 +260,13 @@ impl Encode<ProblemReport> for DocType {
275
260
}
276
261
277
262
e. array ( self . 0 . len ( ) . try_into ( ) . map_err ( |_| {
278
- report. other ( "Unable to encode array length ", CONTEXT ) ;
279
- minicbor:: encode:: Error :: message ( format ! ( "{CONTEXT}, unable to encode array length" ) )
263
+ report. invalid_encoding ( "Array" , "Invalid array" , "Valid array ", CONTEXT ) ;
264
+ minicbor:: encode:: Error :: message ( format ! ( "{CONTEXT}, array length encoding failed " ) )
280
265
} ) ?) ?;
281
266
282
267
for id in & self . 0 {
283
268
id. encode ( e, & mut CborContext :: Tagged ) . map_err ( |_| {
284
- report. other ( "Failed to encode UUIDv4", CONTEXT ) ;
269
+ report. invalid_encoding ( "UUIDv4" , & id . to_string ( ) , "Valid UUIDv4", CONTEXT ) ;
285
270
minicbor:: encode:: Error :: message ( format ! ( "{CONTEXT}: UUIDv4 encoding failed" ) )
286
271
} ) ?;
287
272
}
@@ -317,6 +302,23 @@ impl<'de> Deserialize<'de> for DocType {
317
302
}
318
303
}
319
304
305
+ impl From < DocType > for Value {
306
+ fn from ( value : DocType ) -> Self {
307
+ Value :: Array (
308
+ value
309
+ . 0
310
+ . iter ( )
311
+ . map ( |uuidv4| {
312
+ Value :: Tag (
313
+ UUID_CBOR_TAG ,
314
+ Box :: new ( Value :: Bytes ( uuidv4. uuid ( ) . as_bytes ( ) . to_vec ( ) ) ) ,
315
+ )
316
+ } )
317
+ . collect ( ) ,
318
+ )
319
+ }
320
+ }
321
+
320
322
// This is needed to preserve backward compatibility with the old solution.
321
323
impl PartialEq for DocType {
322
324
fn eq ( & self , other : & Self ) -> bool {
@@ -452,9 +454,9 @@ mod tests {
452
454
#[ test]
453
455
fn test_doc_type_to_value ( ) {
454
456
let uuid = uuid:: Uuid :: new_v4 ( ) ;
455
- let doc_type = DocType ( vec ! [ UuidV4 :: try_from( uuid) . unwrap( ) ] ) ;
457
+ let doc_type: Value = DocType ( vec ! [ UuidV4 :: try_from( uuid) . unwrap( ) ] ) . into ( ) ;
456
458
457
- for d in & doc_type. to_value ( ) . into_array ( ) . unwrap ( ) {
459
+ for d in & doc_type. into_array ( ) . unwrap ( ) {
458
460
let t = d. clone ( ) . into_tag ( ) . unwrap ( ) ;
459
461
assert_eq ! ( t. 0 , UUID_CBOR_TAG ) ;
460
462
assert_eq ! ( t. 1 . as_bytes( ) . unwrap( ) . len( ) , 16 ) ;
0 commit comments