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

[Question] How to use with serde?

Open failable opened this issue 1 year ago • 1 comments

Hi,

When I try to play with the library, I can not figure out how to make it work with serde. How can I fix this? Thanks.

#[macro_use]
extern crate macro_rules_attribute;

fn main() {
    derive_alias! {
        #[derive(Serde!)] = #[derive(serde::Serialize, serde::Deserialize)];
    }

    #[derive(Debug, Clone, Copy, Serde!)]
    struct Foo {
        #[serde(rename = "$id")] // cannot find attribute `serde` in this scope
        pub id: i64,
    }
}

failable avatar May 20 '23 02:05 failable

Yeah, this is currently not supported, due to technical limitations; see https://docs.rs/macro_rules_attribute/0.2.0/macro_rules_attribute/macro.derive_alias.html#caveat-regarding-derive-helpers-inert-made-attributes:

attribute_alias! {
    #[apply(Serde)] = #[derive(::serde::Serialize, ::serde::Deserialize)];
}

#[apply(Serde)]
#[derive(Debug, Clone, Copy)]
struct Foo {
    #[serde(rename = "$id")] // OK
    pub id: i64,
}

danielhenrymantilla avatar May 20 '23 16:05 danielhenrymantilla