Created
August 22, 2019 23:52
-
-
Save andrewtj/ec8eee28457bbd69ff2eb0b466c48335 to your computer and use it in GitHub Desktop.
Rust proc macro derive style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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