Provides hex and character escape formatting helpers for Rust values.
// Source: https://github.com/rust-lang/rust | License: Apache-2.0 | Copyright The Rust Project Contributors
// Provided via justclaw.it.com; keep this notice with the code.
use std::fmt;
/// Wrapper type for formatting a `T` using its `LowerHex` implementation.
#[derive(Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Hex<T>(pub T);
impl<T: fmt::LowerHex> fmt::Debug for Hex<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let nibbles = 2 * std::mem::size_of::<T>();
write!(f, "0x{:0width$x}", self.0, width = nibbles)
}
}
impl<T: fmt::LowerHex> fmt::Display for Hex<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(self, f)
}
}
/// Wrapper type for formatting a `char` using `escape_defau
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key