macro_rules_attribute-rs icon indicating copy to clipboard operation
macro_rules_attribute-rs copied to clipboard

Skip/Exclude some derive items of `derive_alias!`

Open alopatindev opened this issue 1 year ago • 0 comments

For instance we have

use serde::{Serialize, Deserialize};
use speedy::{Readable, Writable};

derive_alias! {
   #[derive(All!)] = #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Readable, Writable)];
}

#[derive(All!)]
struct A;

#[derive(All!)]
enum B;

// ... thousands of types

but few of these types need certain custom trait implementations

impl PartialEq for A { ... }

impl<'a, C> Readable<'a, C> for B { ... }

It'd be convenient to have

  • something like #[derive(All!, ?PartialEq)] (similar to ?Sized)
  • or #[skip_derive(PartialEq)]

in this case.


For now, as far as I get, the only alternatives are copy-pasting of all derive items but custom ones

#[derive(Debug, Clone, Eq, PartialOrd, Ord, Serialize, Deserialize, Readable, Writable)]
struct A;

which is verbose, or something like

derive_alias! {
   #[derive(Base!)] = #[derive(Debug, Clone, PartialEq, Eq, Ord, Serialize, Deserialize, Writable)];
   #[derive(AllButReadable!)] = #[derive(Base!, PartialEq)];
   #[derive(AllButPartialEq!)] = #[derive(Base!, Readable)];
   #[derive(All!)] = #[derive(Base!, PartialEq, Readable)];
}

which leads to combinatorial explosion of unintuitive derive aliases.

Any hope to solve it? Thanks!

alopatindev avatar Oct 28 '23 13:10 alopatindev