non_structural_derive

Crates.ionon_structural_derive
lib.rsnon_structural_derive
version0.1.1
created_at2024-07-31 16:19:54.549546+00
updated_at2025-02-25 14:00:52.700999+00
descriptionnonstructural derives for auto traits
homepage
repositoryhttps://github.com/fee1-dead/non_structural_derive
max_upload_size
id1321078
size5,576
lcnr (lcnr)

documentation

README

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.

Commit count: 8

cargo fmt