Derivative

This crate provides a set of alternative #[derive] attributes for Rust.

Examples

derivative uses attributes to make it possible to derive more implementations than the built-in derive(Trait). Here are a few examples of stuffs you cannot just derive.

You can derive Default on enumerations:

With derivative

Original

{{#playground default-enum.rs}}

{{#playground default-enum-orig.rs}}

You can use different default values for some fields:

With derivative

Original

{{#playground default-value.rs}}

{{#playground default-value-orig.rs}}

Want a transparent Debug implementation for your wrapper? We got that:

With derivative

Original

{{#playground debug-transparent.rs}}

{{#playground debug-transparent-orig.rs}}

Need to ignore a field? We got that too:

With derivative

Original

{{#playground eq-ignore.rs}}

{{#playground eq-ignore-orig.rs}}