macro_rules! forward_lower_exp {
(<$($generic:ident),+> in $this:ty => $field:tt $(,)?) => { ... };
(<$($generic:ident),+> in $this:ty $(,)?) => { ... };
($this:ty => $field:tt $(,)?) => { ... };
($this:ty $(,)?) => { ... };
}Expand description
Implement LowerExp 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 LowerExp bound.
ยงExamples
With a newtype struct:
struct Value(u32);
impl_more::forward_lower_exp!(Value);
assert_eq!(
format!("{:e}", Value(42)),
"4.2e1",
);With a generic newtype struct:
struct Value<T>(T);
impl_more::forward_lower_exp!(<T> in Value<T>);
let inner = 42u32;
assert_eq!(
format!("{:e}", Value(inner)),
"4.2e1",
);Select a named field with => field:
struct Value {
inner: u32,
}
impl_more::forward_lower_exp!(Value => inner);
let value = Value { inner: 42 };
assert_eq!(
format!("{:e}", value),
"4.2e1",
);