@@ -46,21 +46,6 @@ impl DocType {
4646 pub fn doc_types ( & self ) -> & Vec < UuidV4 > {
4747 & self . 0
4848 }
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- }
6449}
6550
6651impl Hash for DocType {
@@ -275,13 +260,13 @@ impl Encode<ProblemReport> for DocType {
275260 }
276261
277262 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 " ) )
280265 } ) ?) ?;
281266
282267 for id in & self . 0 {
283268 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 ) ;
285270 minicbor:: encode:: Error :: message ( format ! ( "{CONTEXT}: UUIDv4 encoding failed" ) )
286271 } ) ?;
287272 }
@@ -317,6 +302,23 @@ impl<'de> Deserialize<'de> for DocType {
317302 }
318303}
319304
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+
320322// This is needed to preserve backward compatibility with the old solution.
321323impl PartialEq for DocType {
322324 fn eq ( & self , other : & Self ) -> bool {
@@ -452,9 +454,9 @@ mod tests {
452454 #[ test]
453455 fn test_doc_type_to_value ( ) {
454456 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 ( ) ;
456458
457- for d in & doc_type. to_value ( ) . into_array ( ) . unwrap ( ) {
459+ for d in & doc_type. into_array ( ) . unwrap ( ) {
458460 let t = d. clone ( ) . into_tag ( ) . unwrap ( ) ;
459461 assert_eq ! ( t. 0 , UUID_CBOR_TAG ) ;
460462 assert_eq ! ( t. 1 . as_bytes( ) . unwrap( ) . len( ) , 16 ) ;
0 commit comments