2 releases

0.1.1 Feb 25, 2025
0.1.0 Jul 31, 2024

#698 in Rust patterns

Download history 1/week @ 2025-03-07 2/week @ 2025-04-11 1/week @ 2025-04-18 1/week @ 2025-05-09 1/week @ 2025-05-16

134 downloads per month

MIT/Apache

4KB

non_structural_derive

A derive-macro replacing the builtin auto-trait implementation with a manual non-recursive one:

struct Foo<T> {
    a: Bar<T>,
    b: Baz,
}

// The builtin auto-trait impl would look like this:
unsafe impl<T> Send for Foo<T>
where
    Bar<T>: Send,
    Baz: Send,
{}

// `#[non_structural_derive(Send)]` emits the the following instead:
unsafe impl<T: Send> Send for Foo<T> {}
fn _check_bound<T: Send>() {}
fn _validate_fields<T: Send>() {
    _check_bound::<Bar<T>>();
    _check_bound::<Baz>();
}

Why would you want this?

The code emitted by non_structural_derive is strictly weaker than the builtin auto-trait impl. It may however improve compile times and avoid overflow errors for very deeply nested types.

Dependencies

~260–710KB
~16K SLoC