-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement flareon::main macro for easy framework bootstrapping
This is the first step in making Flareon an actual "framework" rather than just a library. This macro currently doesn't do much now, but eventually we'd like to have an entire CLI that would be automatically generated for each Flareon project and would allow to do some common operations (run server, run migrations, copy static files to a directory, etc.), as well as allow Flareon users to define their own ones.
- Loading branch information
Showing
15 changed files
with
131 additions
and
100 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
use syn::ItemFn; | ||
|
||
use crate::flareon_ident; | ||
|
||
pub(super) fn fn_to_flareon_main(main_function_decl: ItemFn) -> syn::Result<TokenStream> { | ||
let mut new_main_decl = main_function_decl.clone(); | ||
new_main_decl.sig.ident = | ||
syn::Ident::new("__flareon_main", main_function_decl.sig.ident.span()); | ||
|
||
if !main_function_decl.sig.inputs.is_empty() { | ||
return Err(syn::Error::new_spanned( | ||
main_function_decl.sig.inputs, | ||
"flareon::main function must have zero arguments", | ||
)); | ||
} | ||
|
||
let crate_name = flareon_ident(); | ||
let result = quote! { | ||
fn main() { | ||
let body = async { | ||
let project: #crate_name::FlareonProject = __flareon_main().await.unwrap(); | ||
#crate_name::run_cli(project).await.unwrap(); | ||
|
||
#new_main_decl | ||
}; | ||
#[allow(clippy::expect_used)] | ||
{ | ||
return #crate_name::__private::tokio::runtime::Builder::new_multi_thread() | ||
.enable_all() | ||
.build() | ||
.expect("Failed building the Runtime") | ||
.block_on(body); | ||
} | ||
} | ||
|
||
}; | ||
Ok(result) | ||
} |
Oops, something went wrong.