#inherit #pattern

macro inherits

Improved Practices for the Composition Pattern in Rust

3 releases

0.1.2 Mar 28, 2025
0.1.1 Mar 28, 2025
0.1.0 Mar 7, 2025

#2333 in Procedural macros

Download history 115/week @ 2025-03-05 6/week @ 2025-03-12 245/week @ 2025-03-26 11/week @ 2025-04-02

269 downloads per month
Used in ponsic

MIT license

5KB
68 lines

#[inherits(Type)]

This attribute macro achieves inheritance-like effects through the Deref and DerefMut traits, simplifying the application of the composition pattern in Rust.

A struct annotated with #[inherit(T)] will implicitly contain a parent field of type T, enabling single inheritance behavior.

For disambiguated access to fields with the same name, use (&<name> as &<type>).<field> or (&mut <name> as &mut <type>).<field> syntax.

#[new_type]

This property macro can automatically implement the 'Deref' and 'DerefMut' traits for tuple structs to implement the New-Type pattern

Dependencies

~190–620KB
~15K SLoC