Skip to content

Instantly share code, notes, and snippets.

@andrewtj
Created August 22, 2019 23:52
Show Gist options
  • Save andrewtj/ec8eee28457bbd69ff2eb0b466c48335 to your computer and use it in GitHub Desktop.
Save andrewtj/ec8eee28457bbd69ff2eb0b466c48335 to your computer and use it in GitHub Desktop.
Rust proc macro derive style
// Style A: Single attribute for the crate.
#[derive(yardi::Present, yardi::Parse, /* yardi::..., */ yardi::Rdata)]
#[yardi(rdata_class = "crate::datatypes::Class::IN", rdata_ty = "crate::datatypes::Ty::NAPTR")]
struct Naptr<'a> {
#[doc = "Order: Low numbers are processed before higher numbers."]
pub order: u16,
// ...
#[doc = "Regexp: Substitution expression to apply to the original string to construct the next domain to lookup."]
#[yardi(
present = "|m, e| crate::datatypes::bytes::present_charstr(m, e, 0, 255)",
parse = "|e| crate::datatypes::bytes::parse_charstr(e, 0, 255)",
// ... = ...
)]
pub regexp: std::borrow::Cow<'a, [u8]>,
// ...
}
// Style B: Attribute per macro prefixed with crate name.
#[derive(yardi::Present, yardi::Parse, /* yardi::..., */ yardi::Rdata)]
#[yardi_rdata(class = "crate::datatypes::Class::IN", ty = "crate::datatypes::Ty::NAPTR")]
struct Naptr<'a> {
#[doc = "Order: Low numbers are processed before higher numbers."]
pub order: u16,
// ...
#[doc = "Regexp: Substitution expression to apply to the original string to construct the next domain to lookup."]
#[yardi_present = "|m, e| crate::datatypes::bytes::present_charstr (m, e, 0, 255)"]
#[yardi_parse = "|e| crate::datatypes::bytes::parse_charstr(e, 0, 255)"]
// #[yardi_... = ...]
pub regexp: std::borrow::Cow<'a, [u8]>,
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment