1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 // Provide some more formatting options for some data types (at the moment
14 // that's just `{:x}` for slices of u8).
16 pub struct FmtWrap<T>(pub T);
18 impl<'a> fmt::LowerHex for FmtWrap<&'a [u8]> {
19 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
20 for byte in self.0.iter() {
21 try!(write!(formatter, "{:02x}", byte));
29 let bytes: &[u8] = &[0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef];
30 assert_eq!("0123456789abcdef", &format!("{:x}", FmtWrap(bytes)));