strum icon indicating copy to clipboard operation
strum copied to clipboard

Add `EnumDeref` trait and derive

Open Syndelis opened this issue 1 year ago • 0 comments

About this PR

This PR introduces a new trait and derive EnumDeref for automatically implementing Deref and DerefMut in enumerators composed of new-type-style variants.

Motivation

The primary motivation for this feature is included as one of the tests and doc-tests: "tagged boxes". With this trait, it's possible to avoid the usage of Box<dyn Trait> for grouping structs based on behavior. The advantages of using an enum instead of the former are clear as day:

  • No pointer access;
  • All variants are known at compile time;
  • Possibility of using other strum macros.

Syndelis avatar Nov 18 '23 05:11 Syndelis