Skip to main content

forward_debug

Macro forward_debug 

Source
macro_rules! forward_debug {
    (<$($generic:ident),+> in $($rest:tt)+) => { ... };
    (<const $($rest:tt)+) => { ... };
    (<$generic:ident, $($rest:tt)+) => { ... };
    (@impl [$($generic:tt)+] $this:ty => $field:tt $(,)?) => { ... };
    (@impl [$($generic:tt)+] $this:ty $(,)?) => { ... };
    ($this:ty => $field:tt $(,)?) => { ... };
    ($this:ty $(,)?) => { ... };
}
Expand description

Implement Debug 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 Debug bound.

Declare type and const parameters before in. Const parameters receive no formatting bound.

ยงExamples

With a newtype struct:

struct Value(u32);

impl_more::forward_debug!(Value);

assert_eq!(
    format!("{:?}", Value(42)),
    "42",
);

With a generic newtype struct:

struct Value<T>(T);

impl_more::forward_debug!(<T> in Value<T>);

let inner = 42u32;

assert_eq!(
    format!("{:?}", Value(inner)),
    "42",
);

Select a named field with => field:

struct Value {
    inner: u32,
}

impl_more::forward_debug!(Value => inner);

let value = Value { inner: 42 };

assert_eq!(
    format!("{:?}", value),
    "42",
);

With type and const parameters:

struct Array<T, const N: usize>([T; N]);
impl_more::forward_debug!(<T, const N: usize> in Array<T, N>);

assert_eq!(format!("{:?}", Array([1, 2, 3])), "[1, 2, 3]");