@@ -162,6 +162,42 @@ pub type BE = BigEndian;
162162/// A type alias for [`LittleEndian`].
163163pub type LE = LittleEndian ;
164164
165+ macro_rules! impl_dbg_trait {
166+ ( $name: ident, $native: ident) => {
167+ impl <O : ByteOrder > Debug for $name<O > {
168+ #[ inline]
169+ fn fmt( & self , f: & mut Formatter <' _>) -> fmt:: Result {
170+ // This results in a format like "U16(42)".
171+ f. debug_tuple( stringify!( $name) ) . field( & self . get( ) ) . finish( )
172+ }
173+ }
174+ } ;
175+ }
176+
177+ macro_rules! impl_dbg_traits {
178+ ( $name: ident, $native: ident, "floating point number" ) => {
179+ #[ cfg( not( no_fp_fmt_parse) ) ]
180+ impl_dbg_trait!( $name, $native) ;
181+
182+ #[ cfg( no_fp_fmt_parse) ]
183+ impl <O : ByteOrder > Debug for $name<O > {
184+ #[ inline]
185+ fn fmt( & self , _f: & mut Formatter <' _>) -> fmt:: Result {
186+ panic!( "floating point support is turned off" ) ;
187+ }
188+ }
189+ } ;
190+ ( $name: ident, $native: ident, "unsigned integer" ) => {
191+ impl_dbg_traits!( $name, $native, @all_types) ;
192+ } ;
193+ ( $name: ident, $native: ident, "signed integer" ) => {
194+ impl_dbg_traits!( $name, $native, @all_types) ;
195+ } ;
196+ ( $name: ident, $native: ident, @all_types) => {
197+ impl_dbg_trait!( $name, $native) ;
198+ } ;
199+ }
200+
165201macro_rules! impl_fmt_trait {
166202 ( $name: ident, $native: ident, $trait: ident) => {
167203 impl <O : ByteOrder > $trait for $name<O > {
@@ -175,6 +211,7 @@ macro_rules! impl_fmt_trait {
175211
176212macro_rules! impl_fmt_traits {
177213 ( $name: ident, $native: ident, "floating point number" ) => {
214+ #[ cfg( not( no_fp_fmt_parse) ) ]
178215 impl_fmt_trait!( $name, $native, Display ) ;
179216 } ;
180217 ( $name: ident, $native: ident, "unsigned integer" ) => {
@@ -686,16 +723,9 @@ example of how it can be used for parsing UDP packets.
686723 }
687724 }
688725
726+ impl_dbg_traits!( $name, $native, $number_kind) ;
689727 impl_fmt_traits!( $name, $native, $number_kind) ;
690728 impl_ops_traits!( $name, $native, $number_kind) ;
691-
692- impl <O : ByteOrder > Debug for $name<O > {
693- #[ inline]
694- fn fmt( & self , f: & mut Formatter <' _>) -> fmt:: Result {
695- // This results in a format like "U16(42)".
696- f. debug_tuple( stringify!( $name) ) . field( & self . get( ) ) . finish( )
697- }
698- }
699729 } ;
700730}
701731
0 commit comments