std::fmt::LowerHex - Rust (original) (raw)
Trait std::fmt::LowerHex1.0.0 [−] [src]
pub trait LowerHex { fn fmt(&self, f: &mut Formatter) -> Result<(), Error>; }
x
formatting.
The LowerHex
trait should format its output as a number in hexadecimal, with a
through f
in lower case.
For primitive signed integers (i8
to i128
, and isize
), negative values are formatted as the two’s complement representation.
The alternate flag, #
, adds a 0x
in front of the output.
For more information on formatters, see the module-level documentation.
Basic usage with i32
:
let x = 42;
assert_eq!(format!("{:x}", x), "2a"); assert_eq!(format!("{:#x}", x), "0x2a");
assert_eq!(format!("{:x}", -16), "fffffff0");Run
Implementing LowerHex
on a type:
use std::fmt;
struct Length(i32);
impl fmt::LowerHex for Length { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let val = self.0;
write!(f, "{:x}", val)
}
}
let l = Length(9);
println!("l as hex is: {:x}", l);Run
impl LowerHex for [u8](../primitive.u8.html)
impl LowerHex for [u64](../primitive.u64.html)
impl LowerHex for [u16](../primitive.u16.html)
impl<'a, T> LowerHex for [&'a ](../primitive.reference.html)T where T: [LowerHex](../../std/fmt/trait.LowerHex.html "trait std::fmt::LowerHex") + ?[Sized](../../std/marker/trait.Sized.html "trait std:📑:Sized"),
impl LowerHex for [i128](../primitive.i128.html)
impl LowerHex for [u128](../primitive.u128.html)
impl LowerHex for [usize](../primitive.usize.html)
impl LowerHex for [i16](../primitive.i16.html)
impl<'a, T> LowerHex for [&'a mut ](../primitive.reference.html)T where T: [LowerHex](../../std/fmt/trait.LowerHex.html "trait std::fmt::LowerHex") + ?[Sized](../../std/marker/trait.Sized.html "trait std:📑:Sized"),
impl LowerHex for [i32](../primitive.i32.html)
impl LowerHex for [isize](../primitive.isize.html)
impl LowerHex for [u32](../primitive.u32.html)
impl LowerHex for [i8](../primitive.i8.html)
impl LowerHex for [i64](../primitive.i64.html)
impl<T> LowerHex for [Wrapping](../../std/num/struct.Wrapping.html "struct std::num::Wrapping")<T> where T: [LowerHex](../../std/fmt/trait.LowerHex.html "trait std::fmt::LowerHex"),