File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 37
37
- type ` &[u8] -> String `
38
38
39
39
#### ` hex ` Prefixed Functions
40
+ - Convert ` HexBytes ` to ` Hex `
41
+ - type ` &[u8] -> &str `
42
+ - e.g. ` b"0x..." -> "0x..." `
40
43
- Build fixed length ` Array ` from ` Hex `
41
44
- type ` &str -> [u8; N] `
42
45
- Convert ` Hex ` to ` Bytes `
Original file line number Diff line number Diff line change @@ -231,6 +231,22 @@ pub fn hex_bytes2hex_str(bytes: &[u8]) -> ArrayBytesResult<&str> {
231
231
} )
232
232
}
233
233
234
+ /// Just like [`hex_bytes2hex_str`] but without the checking.
235
+ ///
236
+ /// # Examples
237
+ /// ```
238
+ /// assert_eq!(
239
+ /// array_bytes::hex_bytes2hex_str_unchecked(b"0x4c6f7665204a616e6520466f7265766572"),
240
+ /// "0x4c6f7665204a616e6520466f7265766572",
241
+ /// );
242
+ /// ```
243
+ pub fn hex_bytes2hex_str_unchecked ( bytes : & [ u8 ] ) -> & str {
244
+ unsafe {
245
+ #[ allow( clippy:: transmute_bytes_to_str) ]
246
+ mem:: transmute ( bytes)
247
+ }
248
+ }
249
+
234
250
/// [`Bytes`] to [`Hex`].
235
251
///
236
252
/// # Examples
Original file line number Diff line number Diff line change @@ -103,6 +103,18 @@ fn hex_bytes2hex_str_should_work() {
103
103
) ;
104
104
}
105
105
106
+ #[ test]
107
+ fn hex_bytes2hex_str_unchecked_should_work ( ) {
108
+ assert_eq ! (
109
+ hex_bytes2hex_str_unchecked( b"0x4c6f7665204a616e6520466f7265766572" ) ,
110
+ "0x4c6f7665204a616e6520466f7265766572" ,
111
+ ) ;
112
+ assert_eq ! (
113
+ hex_bytes2hex_str_unchecked( b"4c6f7665204a616e6520466f7265766572" ) ,
114
+ "4c6f7665204a616e6520466f7265766572" ,
115
+ ) ;
116
+ }
117
+
106
118
#[ test]
107
119
fn hex2array_should_work ( ) {
108
120
assert_eq ! ( hex2array( "0x4c6f7665204a616e6520466f7265766572" ) , Ok ( * b"Love Jane Forever" ) ) ;
You can’t perform that action at this time.
0 commit comments