Skip to content

Commit

Permalink
[fix] add manyhow for TokenStream conversion & error handling
Browse files Browse the repository at this point in the history
Signed-off-by: VAmuzing <[email protected]>
  • Loading branch information
VAmuzing authored and mversic committed Dec 13, 2023
1 parent 729ddb5 commit 86c730f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ proc-macro = true
syn2 = { workspace = true }
quote = { workspace = true }
proc-macro2 = { workspace = true }
manyhow = { workspace = true }

[dev-dependencies]
warp = { workspace = true }
15 changes: 7 additions & 8 deletions cli/derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Crate with a proc macro for torii endpoint generation
use proc_macro::TokenStream;
use proc_macro2::Span;
use manyhow::{manyhow, Result};
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn2::{
parse::{Parse, ParseStream},
parse_macro_input,
punctuated::Punctuated,
Ident, LitInt, Token,
};
Expand Down Expand Up @@ -50,9 +49,10 @@ use syn2::{
/// // defaults, such as `endpoint3`.
/// generate_endpoints!(3, my_endpoint: 2, 4, anotherOne: 5, );
/// ```
#[manyhow]
#[proc_macro]
pub fn generate_endpoints(input: TokenStream) -> TokenStream {
let EndpointList(list) = parse_macro_input!(input as EndpointList);
pub fn generate_endpoints(input: TokenStream) -> Result<TokenStream> {
let EndpointList(list) = syn2::parse2(input)?;
let lazy_arg_names = (1_u8..).map(|count| {
Ident::new(
format!("__endpoint_arg_{count}").as_str(),
Expand Down Expand Up @@ -107,10 +107,9 @@ pub fn generate_endpoints(input: TokenStream) -> TokenStream {
endpoints.push(expanded);
}

quote! {
Ok(quote! {
#( #endpoints )*
}
.into()
})
}

#[derive(Debug)]
Expand Down

0 comments on commit 86c730f

Please sign in to comment.