Repository: actix/actix-web
File: actix-web-codegen/src/route.rs (Rust)

Code before:
            ast,
            resource_type,
            guard,
        })
    }
}

impl ToTokens for Route {
    fn to_tokens(&self, output: &mut TokenStream2) {
        let Self {
            name,
            guard,
            ast,
            args:
                Args {
                    path,
                    guards,
                    wrappers,
                    methods,
                },
            resource_type,
        } = self;
        let resource_name = name.to_string();
        let methods = methods.iter();

        let guard_gen = if guard == &GuardType::Multi {
            quote! {
                .guard(actix_web::guard::AnyGuard::new(vec![#(Box::new(actix_web::guard::#methods())),*]))
            }
        } else {
            quote! {
                .guard(actix_web::guard::#guard())
            }
        };

        let stream = quote! {
            #[allow(non_camel_case_types, missing_docs)]
            pub struct #name;

            impl actix_web::dev::HttpServiceFactory for #name {
                fn register(self, __config: &mut actix_web::dev::AppService) {
                    #ast
                    let __resource = actix_web::Resource::new(#path)
                        .name(#resource_name)
                        #guard_gen
                        #(.guard(actix_web::guard::fn_guard(#guards)))*
                        #(.wrap(#wrappers))*
                        .#resource_type(#name);

                    actix_web::dev::HttpServiceFactory::register(__resource, __config)
                }

Review comment (suggestion):
For a one-byte types it's better to derive `Copy` and compare them by value, rather than using references.

Code after:
            args,
            ast,
            resource_type,
            guard,
        })
    }
}

impl ToTokens for Route {
    fn to_tokens(&self, output: &mut TokenStream2) {
        let Self {
            name,
            guard,
            ast,
            args:
                Args {
                    path,
                    guards,
                    wrappers,
                    methods,
                },
            resource_type,
        } = self;
        let resource_name = name.to_string();
        let mut methods = methods.iter();

        let method_guards = if *guard == GuardType::Multi {
            // unwrapping since length is checked to be at least one
            let first = methods.next().unwrap();

            quote! {
                .guard(
                    actix_web::guard::Any(actix_web::guard::#first())
                        #(.or(actix_web::guard::#methods()))*
                )
            }
        } else {
            quote! {
                .guard(actix_web::guard::#guard())
            }
        };

        let stream = quote! {
            #[allow(non_camel_case_types, missing_docs)]
            pub struct #name;

            impl actix_web::dev::HttpServiceFactory for #name {
                fn register(self, __config: &mut actix_web::dev::AppService) {
                    #ast
                    let __resource = actix_web::Resource::new(#path)
                        .name(#resource_name)