macro_rules! forward_upper_hex {
(<$($generic:ident),+> in $this:ty => $field:tt $(,)?) => { ... };
(<$($generic:ident),+> in $this:ty $(,)?) => { ... };
($this:ty => $field:tt $(,)?) => { ... };
($this:ty $(,)?) => { ... };
}Expand description
Implement UpperHex by forwarding to a field.
The formatter is passed through unchanged. Emitted code supports no_std.
Omit the field for a tuple newtype. All type parameters receive a UpperHex bound.
ยงExamples
With a newtype struct:
struct Value(u32);
impl_more::forward_upper_hex!(Value);
assert_eq!(
format!("{:X}", Value(42)),
"2A",
);With a generic newtype struct:
struct Value<T>(T);
impl_more::forward_upper_hex!(<T> in Value<T>);
let inner = 42u32;
assert_eq!(
format!("{:X}", Value(inner)),
"2A",
);Select a named field with => field:
struct Value {
inner: u32,
}
impl_more::forward_upper_hex!(Value => inner);
let value = Value { inner: 42 };
assert_eq!(
format!("{:X}", value),
"2A",
);