macro_rules! forward_pointer {
(<$($generic:ident),+> in $this:ty => $field:tt $(,)?) => { ... };
(<$($generic:ident),+> in $this:ty $(,)?) => { ... };
($this:ty => $field:tt $(,)?) => { ... };
($this:ty $(,)?) => { ... };
}Expand description
Implement Pointer 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 Pointer bound.
ยงExamples
With a newtype struct:
struct Value(*const i32);
impl_more::forward_pointer!(Value);
assert_eq!(
format!("{:p}", Value(core::ptr::null())),
"0x0",
);With a generic newtype struct:
struct Value<T>(T);
impl_more::forward_pointer!(<T> in Value<T>);
let inner = core::ptr::null::<i32>();
assert_eq!(
format!("{:p}", Value(inner)),
"0x0",
);Select a named field with => field:
struct Value {
inner: *const i32,
}
impl_more::forward_pointer!(Value => inner);
let value = Value { inner: core::ptr::null() };
assert_eq!(
format!("{:p}", value),
"0x0",
);