blob: fed7b682f4a85eae7c6d4083495831bd85569a85 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse, ItemStruct};
#[proc_macro_derive(Serialize)]
pub fn derive_serialize(item: TokenStream) -> TokenStream {
let ast: ItemStruct = parse(item).unwrap();
let name = ast.ident;
quote!(
impl Serialize for #name {
fn serialize<W: std::io::Write>(&self, w: W) -> io::Result<()> {
w.write_all(&[42])?;
Ok(())
}
}
)
.into()
}
|