use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use crate::parser::command_spec::{DocNamedType, Structure};
impl Structure {
pub fn to_rust(&self) -> TokenStream2 {
let doc_comments: TokenStream2 = self
.attributes
.iter()
.map(|attr| attr.to_rust(&self.identifier))
.collect();
let ident = &self.identifier.to_rust();
let contents: Vec<TokenStream2> = self
.contents
.iter()
.filter_map(|a| DocNamedType::to_rust(a))
.collect();
let c_ident = self.identifier.to_c_paired();
let convertible = self.derive_convertible(&c_ident);
let into_impl = self.derive_from_rust_paired_c(&c_ident);
quote! {
#doc_comments
#[allow(non_camel_case_types)]
#[derive(Debug)]
pub struct #ident {
#(#contents),*
}
#convertible
#into_impl
}
}
}