49 lines
1.1 KiB
Rust
49 lines
1.1 KiB
Rust
use syn;
|
|
use quote;
|
|
|
|
pub fn impl_rr_data(ast: &syn::DeriveInput) -> quote::Tokens {
|
|
if !ast.generics.ty_params.is_empty() {
|
|
panic!("Type parameters not supported for deriving RRData");
|
|
}
|
|
|
|
if !ast.generics.where_clause.predicates.is_empty() {
|
|
panic!("Where clauses not supported for deriving RRData");
|
|
}
|
|
|
|
if !ast.generics.lifetimes.is_empty() {
|
|
panic!("Lifetimes not supported for deriving RRData");
|
|
}
|
|
|
|
let name = &ast.ident;
|
|
let name_str: &str = name.as_ref();
|
|
|
|
let test_mod_name = syn::Ident::from(format!("test_rr_{}", name));
|
|
|
|
quote!{
|
|
impl ::dnsbox_base::ser::RRData for #name {
|
|
fn rr_type() -> ::dnsbox_base::common_types::Type {
|
|
::dnsbox_base::records::types::#name
|
|
}
|
|
|
|
fn rr_type_name() -> ::std::borrow::Cow<'static, str> {
|
|
::std::borrow::Cow::Borrowed(#name_str)
|
|
}
|
|
}
|
|
|
|
// #[cfg(test)]
|
|
#[allow(non_snake_case, unused_imports)]
|
|
mod #test_mod_name {
|
|
use ::dnsbox_base::records::registry;
|
|
use ::dnsbox_base::records::types;
|
|
|
|
#[test]
|
|
fn test_registry() {
|
|
assert_eq!(
|
|
registry::known_name_to_type(#name_str),
|
|
Some(types::#name)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|