1515//! # Hex encoding and decoding
1616//!
1717
18+ #[ cfg( feature = "no-std" ) ]
19+ use alloc:: { format, string:: String , vec:: Vec } ;
20+
1821use core:: { fmt, str} ;
1922use Hash ;
2023
@@ -40,7 +43,7 @@ impl fmt::Display for Error {
4043}
4144
4245/// Trait for objects that can be serialized as hex strings
43- #[ cfg( any( test, feature = "std" ) ) ]
46+ #[ cfg( any( test, feature = "std" , feature = "no-std" ) ) ]
4447pub trait ToHex {
4548 /// Hex representation of the object
4649 fn to_hex ( & self ) -> String ;
@@ -60,7 +63,7 @@ pub trait FromHex: Sized {
6063 }
6164}
6265
63- #[ cfg( any( test, feature = "std" ) ) ]
66+ #[ cfg( any( test, feature = "std" , feature = "no-std" ) ) ]
6467impl < T : fmt:: LowerHex > ToHex for T {
6568 /// Outputs the hash in hexadecimal form
6669 fn to_hex ( & self ) -> String {
@@ -174,7 +177,7 @@ pub fn format_hex_reverse(data: &[u8], f: &mut fmt::Formatter) -> fmt::Result {
174177 Ok ( ( ) )
175178}
176179
177- #[ cfg( any( test, feature = "std" ) ) ]
180+ #[ cfg( any( test, feature = "std" , feature = "no-std" ) ) ]
178181impl ToHex for [ u8 ] {
179182 fn to_hex ( & self ) -> String {
180183 use core:: fmt:: Write ;
@@ -186,7 +189,7 @@ impl ToHex for [u8] {
186189 }
187190}
188191
189- #[ cfg( any( test, feature = "std" ) ) ]
192+ #[ cfg( any( test, feature = "std" , feature = "no-std" ) ) ]
190193impl FromHex for Vec < u8 > {
191194 fn from_byte_iter < I > ( iter : I ) -> Result < Self , Error >
192195 where I : Iterator < Item =Result < u8 , Error > > +
0 commit comments