-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
36 lines (30 loc) · 1.3 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#![allow(dead_code)]
extern crate lean_buffer_internal as internal;
use std::str::FromStr;
use darling::FromDeriveInput;
use proc_macro::TokenStream;
use syn::DeriveInput;
use internal::core::InputReceiver;
#[proc_macro_derive(LeanBufferWrite)]
pub fn derive_fb_code_then_write(input: TokenStream) -> TokenStream {
let mut out = TokenStream::new();
// yes, nasty hack, to wrap code generation
out.extend(TokenStream::from_str("#[derive(LeanBufferInternal)]"));
out.extend(input.clone());
let parsed = syn::parse::<DeriveInput>(out).expect("crash");
let mut receiver = InputReceiver::from_derive_input(&parsed).expect("crash");
receiver.write_to_out_dir(None, None, None);
TokenStream::new()
}
/// Not-prettified output, will be collated later, then hopefully prettified
#[proc_macro_derive(LeanBufferRaw)]
pub fn derive_fb_code_then_write_raw(input: TokenStream) -> TokenStream {
let mut out = TokenStream::new();
// yes, nasty hack, to wrap code generation
out.extend(TokenStream::from_str("#[derive(LeanBufferInternal)]"));
out.extend(input.clone());
let parsed = syn::parse::<DeriveInput>(out).expect("crash");
let mut receiver = InputReceiver::from_derive_input(&parsed).expect("crash");
receiver.write_raw_to_out_dir(None, None, None);
TokenStream::new()
}