mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-26 06:57:43 +02:00
apply standard formatting
This commit is contained in:
@ -153,37 +153,37 @@ pub fn routes(_: TokenStream, input: TokenStream) -> TokenStream {
|
||||
|
||||
macro_rules! method_macro {
|
||||
($variant:ident, $method:ident) => {
|
||||
#[doc = concat!("Creates route handler with `actix_web::guard::", stringify!($variant), "`.")]
|
||||
///
|
||||
/// # Syntax
|
||||
/// ```plain
|
||||
#[doc = concat!("#[", stringify!($method), r#"("path"[, attributes])]"#)]
|
||||
/// ```
|
||||
///
|
||||
/// # Attributes
|
||||
/// - `"path"`: Raw literal string with path for which to register handler.
|
||||
/// - `name = "resource_name"`: Specifies resource name for the handler. If not set, the function
|
||||
/// name of handler is used.
|
||||
/// - `guard = "function_name"`: Registers function as guard using `actix_web::guard::fn_guard`.
|
||||
/// - `wrap = "Middleware"`: Registers a resource middleware.
|
||||
///
|
||||
/// # Notes
|
||||
/// Function name can be specified as any expression that is going to be accessible to the
|
||||
/// generate code, e.g `my_guard` or `my_module::my_guard`.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// # use actix_web::HttpResponse;
|
||||
#[doc = concat!("# use actix_web_codegen::", stringify!($method), ";")]
|
||||
#[doc = concat!("#[", stringify!($method), r#"("/")]"#)]
|
||||
/// async fn example() -> HttpResponse {
|
||||
/// HttpResponse::Ok().finish()
|
||||
/// }
|
||||
/// ```
|
||||
#[proc_macro_attribute]
|
||||
pub fn $method(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
route::with_method(Some(route::MethodType::$variant), args, input)
|
||||
}
|
||||
#[doc = concat!("Creates route handler with `actix_web::guard::", stringify!($variant), "`.")]
|
||||
///
|
||||
/// # Syntax
|
||||
/// ```plain
|
||||
#[doc = concat!("#[", stringify!($method), r#"("path"[, attributes])]"#)]
|
||||
/// ```
|
||||
///
|
||||
/// # Attributes
|
||||
/// - `"path"`: Raw literal string with path for which to register handler.
|
||||
/// - `name = "resource_name"`: Specifies resource name for the handler. If not set, the
|
||||
/// function name of handler is used.
|
||||
/// - `guard = "function_name"`: Registers function as guard using `actix_web::guard::fn_guard`.
|
||||
/// - `wrap = "Middleware"`: Registers a resource middleware.
|
||||
///
|
||||
/// # Notes
|
||||
/// Function name can be specified as any expression that is going to be accessible to the
|
||||
/// generate code, e.g `my_guard` or `my_module::my_guard`.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// # use actix_web::HttpResponse;
|
||||
#[doc = concat!("# use actix_web_codegen::", stringify!($method), ";")]
|
||||
#[doc = concat!("#[", stringify!($method), r#"("/")]"#)]
|
||||
/// async fn example() -> HttpResponse {
|
||||
/// HttpResponse::Ok().finish()
|
||||
/// }
|
||||
/// ```
|
||||
#[proc_macro_attribute]
|
||||
pub fn $method(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
route::with_method(Some(route::MethodType::$variant), args, input)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -488,31 +488,32 @@ pub(crate) fn with_methods(input: TokenStream) -> TokenStream {
|
||||
|
||||
ast.attrs = others.into_iter().map(Result::unwrap_err).collect();
|
||||
|
||||
let methods =
|
||||
match methods
|
||||
.into_iter()
|
||||
.map(Result::unwrap)
|
||||
.map(|(method, attr)| {
|
||||
attr.parse_meta().and_then(|args| {
|
||||
if let Meta::List(args) = args {
|
||||
Args::new(args.nested.into_iter().collect(), Some(method))
|
||||
} else {
|
||||
Err(syn::Error::new_spanned(attr, "Invalid input for macro"))
|
||||
}
|
||||
})
|
||||
let methods = match methods
|
||||
.into_iter()
|
||||
.map(Result::unwrap)
|
||||
.map(|(method, attr)| {
|
||||
attr.parse_meta().and_then(|args| {
|
||||
if let Meta::List(args) = args {
|
||||
Args::new(args.nested.into_iter().collect(), Some(method))
|
||||
} else {
|
||||
Err(syn::Error::new_spanned(attr, "Invalid input for macro"))
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
{
|
||||
Ok(methods) if methods.is_empty() => return input_and_compile_error(
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
{
|
||||
Ok(methods) if methods.is_empty() => {
|
||||
return input_and_compile_error(
|
||||
input,
|
||||
syn::Error::new(
|
||||
Span::call_site(),
|
||||
"The #[routes] macro requires at least one `#[<method>(..)]` attribute.",
|
||||
),
|
||||
),
|
||||
Ok(methods) => methods,
|
||||
Err(err) => return input_and_compile_error(input, err),
|
||||
};
|
||||
)
|
||||
}
|
||||
Ok(methods) => methods,
|
||||
Err(err) => return input_and_compile_error(input, err),
|
||||
};
|
||||
|
||||
match Route::multiple(methods, ast) {
|
||||
Ok(route) => route.into_token_stream().into(),
|
||||
|
Reference in New Issue
Block a user