Skip to content

Commit

Permalink
Format Rust code using rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 23, 2024
1 parent 28a2320 commit 678c9a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion crates/craft-macros/examples/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Service {
pub(crate) fn add2(
self: ::std::sync::Arc<Self>,
left: QueryParam<i64, true>,
right: QueryParam<i64, true>
right: QueryParam<i64, true>,
) -> String {
(self.state + *left + *right).to_string()
}
Expand Down
40 changes: 15 additions & 25 deletions crates/craft-macros/src/craft.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
use crate::utils::salvo_crate;
use proc_macro2::{ Span, TokenStream };
use quote::{ quote, ToTokens };
use proc_macro2::{Span, TokenStream};
use quote::{quote, ToTokens};
use syn::{
parse::Parser,
parse_quote,
Attribute,
FnArg,
Ident,
ImplItem,
ImplItemFn,
Item,
Token,
Type,
parse::Parser, parse_quote, Attribute, FnArg, Ident, ImplItem, ImplItemFn, Item, Token, Type,
};

pub(crate) fn generate(input: Item) -> syn::Result<TokenStream> {
Expand All @@ -25,20 +16,21 @@ pub(crate) fn generate(input: Item) -> syn::Result<TokenStream> {
Ok(item_impl.into_token_stream())
}
Item::Fn(_) => Ok(input.into_token_stream()),
_ => Err(syn::Error::new_spanned(input, "#[craft] must added to `impl`")),
_ => Err(syn::Error::new_spanned(
input,
"#[craft] must added to `impl`",
)),
}
}

fn take_method_macro(item_fn: &mut ImplItemFn) -> syn::Result<Option<Attribute>> {
let mut index: Option<usize> = None;
let mut new_attr: Option<Attribute> = None;
for (idx, attr) in &mut item_fn.attrs.iter().enumerate() {
if
!(match attr.path().segments.last() {
Some(segment) => segment.ident.to_string() == "craft",
None => false,
})
{
if !(match attr.path().segments.last() {
Some(segment) => segment.ident.to_string() == "craft",
None => false,
}) {
continue;
}
if let Some((_, last)) = attr.to_token_stream().to_string().split_once("craft(") {
Expand Down Expand Up @@ -90,12 +82,10 @@ impl MethodStyle {
if ty.ends_with("::Arc<Self>") {
Ok(Self::ArcSelf)
} else {
Err(
syn::Error::new_spanned(
method,
"#[craft] method receiver must be '&self', 'Arc<Self>' or '&Arc<Self>'"
)
)
Err(syn::Error::new_spanned(
method,
"#[craft] method receiver must be '&self', 'Arc<Self>' or '&Arc<Self>'",
))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/craft-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod craft;
mod utils;

use proc_macro::TokenStream;
use syn::{ parse_macro_input, Item };
use syn::{parse_macro_input, Item};

/// `#[craft]` is an attribute macro used to batch convert methods in an `impl` block into [`Salvo`'s `Handler`](https://github.com/salvo-rs/salvo).
///
Expand Down
2 changes: 1 addition & 1 deletion crates/craft/examples/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Service {
pub(crate) fn add2(
self: ::std::sync::Arc<Self>,
left: QueryParam<i64, true>,
right: QueryParam<i64, true>
right: QueryParam<i64, true>,
) -> String {
(self.state + *left + *right).to_string()
}
Expand Down

0 comments on commit 678c9a6

Please sign in to comment.