-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ae7766
commit e7fb839
Showing
8 changed files
with
120 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::utils::format_fn_wrapper; | ||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
use syn::{ | ||
parse::{Parse, ParseStream}, | ||
Path, PathArguments, | ||
}; | ||
|
||
pub struct FnDatatypeInput { | ||
function: Path, | ||
} | ||
|
||
impl Parse for FnDatatypeInput { | ||
fn parse(input: ParseStream<'_>) -> syn::Result<Self> { | ||
Ok(Self { | ||
function: input.parse()?, | ||
}) | ||
} | ||
} | ||
|
||
pub fn proc_macro(FnDatatypeInput { function }: FnDatatypeInput) -> syn::Result<TokenStream> { | ||
let mut specta_fn_macro = function.clone(); | ||
|
||
let last = specta_fn_macro | ||
.segments | ||
.last_mut() | ||
.expect("Function path is empty!"); | ||
|
||
last.ident = format_fn_wrapper(&last.ident.clone()); | ||
last.arguments = PathArguments::None; | ||
|
||
// `type_map` is defined by `specta::fn_datatype!` which invokes this. | ||
Ok(quote! { | ||
// This defines `export` | ||
#specta_fn_macro!(@export_fn; #function); | ||
|
||
// `let` is to workaround: error: macro expansion ignores token `;` and any following | ||
let result = export(type_map); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters