Files
bytes/src/fmt/hex.rs
T

28 lines
595 B
Rust
Raw Normal View History

use core::fmt::{Formatter, LowerHex, Result, UpperHex};
2019-07-31 07:50:57 +08:00
2020-01-24 02:08:40 +08:00
use super::BytesRef;
2020-05-22 13:17:30 +09:00
use crate::{Bytes, BytesMut};
2019-07-31 07:50:57 +08:00
2020-01-24 02:08:40 +08:00
impl LowerHex for BytesRef<'_> {
2019-07-31 07:50:57 +08:00
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
2020-01-24 02:08:40 +08:00
for &b in self.0 {
2019-07-31 07:50:57 +08:00
write!(f, "{:02x}", b)?;
}
Ok(())
}
}
2020-01-24 02:08:40 +08:00
impl UpperHex for BytesRef<'_> {
2019-07-31 07:50:57 +08:00
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
2020-01-24 02:08:40 +08:00
for &b in self.0 {
2019-07-31 07:50:57 +08:00
write!(f, "{:02X}", b)?;
}
Ok(())
}
}
fmt_impl!(LowerHex, Bytes);
fmt_impl!(LowerHex, BytesMut);
fmt_impl!(UpperHex, Bytes);
fmt_impl!(UpperHex, BytesMut);