@@ -25,14 +25,14 @@ use alloc::boxed::Box;
2525use alloc:: vec:: Vec ;
2626use core:: borrow:: { Borrow , BorrowMut } ;
2727use core:: convert:: TryFrom ;
28- use core:: fmt:: { self , Display , Formatter } ;
28+ use core:: fmt:: { self , Debug , Display , Formatter } ;
2929use core:: ops:: Range ;
3030
3131use amplify:: confinement:: { SmallBlob , TinyBlob } ;
3232use amplify:: num:: error:: OverflowError ;
3333
3434/// Large binary bytestring object.
35- #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
35+ #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
3636pub struct ByteStr {
3737 /// Adjusted slice length.
3838 len : u16 ,
@@ -155,12 +155,27 @@ impl ByteStr {
155155 pub fn to_vec ( & self ) -> Vec < u8 > { self . as_ref ( ) . to_vec ( ) }
156156}
157157
158+ #[ cfg( not( feature = "std" ) ) ]
159+ impl Debug for ByteStr {
160+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result { write ! ( f, "{:#04X?}" , self . as_ref( ) ) }
161+ }
162+
163+ #[ cfg( feature = "std" ) ]
164+ impl Debug for ByteStr {
165+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
166+ use amplify:: hex:: ToHex ;
167+
168+ f. debug_tuple ( "ByteStr" ) . field ( & self . as_ref ( ) . to_hex ( ) ) . finish ( )
169+ }
170+ }
171+
158172#[ cfg( feature = "std" ) ]
159173impl Display for ByteStr {
160174 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
161175 use std:: fmt:: Write ;
162176
163177 use amplify:: hex:: ToHex ;
178+
164179 let vec = Vec :: from ( & self . bytes [ ..self . len as usize ] ) ;
165180 if f. alternate ( ) {
166181 for ( line, slice) in self . as_ref ( ) . chunks ( 16 ) . enumerate ( ) {
@@ -207,9 +222,7 @@ impl Display for ByteStr {
207222
208223#[ cfg( not( feature = "std" ) ) ]
209224impl Display for ByteStr {
210- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
211- write ! ( f, "{:#04X?}" , & self . bytes[ 0usize ..self . len as usize ] )
212- }
225+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result { write ! ( f, "{:#04X?}" , self . as_ref( ) ) }
213226}
214227
215228/*
0 commit comments