obstruct_macros/lib.rs
1extern crate proc_macro;
2
3use proc_macro::TokenStream;
4use syn::parse_macro_input;
5
6mod instruct;
7mod destruct;
8
9/// Expand an expression `instruct!{ x: 7, y: 9 }`
10///
11/// This expression is meant to be analogous to `FooBar { x: 7, y: 9 }`, except with an anonymous `struct`
12/// instead of `FooBar`
13#[proc_macro]
14pub fn instruct(input: TokenStream) -> TokenStream {
15 let contents = parse_macro_input!(input as instruct::InstructStruct);
16 contents.transform()
17}
18
19/// Expand an expression `call!{ foo {x: 7, y: 9} }`
20#[proc_macro]
21pub fn call(input: TokenStream) -> TokenStream {
22 let contents = parse_macro_input!(input as instruct::InstructFunctionCall);
23 contents.transform()
24}
25
26
27/// Expand a pattern `destruct!{let {x, y} = foo}`
28///
29/// This pattern is meant to be analogous to `let FooBar {x, y} = foo`, except with an anonymous `struct`
30///
31/// # Missing features
32///
33/// - ref
34/// - mut
35/// - any kind of `let else`.
36/// - inner patterns
37/// - renamings
38/// - `..`
39/// - `_`
40/// - default values
41#[proc_macro]
42pub fn destruct(input: TokenStream) -> TokenStream {
43 destruct::Destruct::transform(input)
44}