macro_rules_attribute-rs
macro_rules_attribute-rs copied to clipboard
[Question] How to use with serde?
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,
}
}
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,
}