[][src]Attribute Macro actix_web_cute_codegen::scope

#[scope]

Generates scope

Syntax: #[scope("path"[, attributes])]

Due to current limitation it cannot be applied to modules themself. Instead one should create const variable that contains module code.

Attributes:

  • "path" - Raw literal string with path for which to register handler. Mandatory.
  • hook="function_name" - Registers function to be run on scope before registering everything else.
  • guard="function_name" - Registers function as guard using actix_web::guard::fn_guard
  • hanlder="function_name" - Registers route hanlder as part of scope.

Special members:

  • #[hook] functions - are going to be run on scope before registering everything else
  • #[guard] functions - specifies function to be passed to guard_fn.
  • init - Scope initialization function. Used as hook
  • default_resource - function will be used as default method to the scope.

Example

use actix_web_cute_codegen::{scope};

#[scope("/scope")]
const mod_inner: () = {
    use actix_web_cute_codegen::{get, hook};
    use actix_web::{HttpResponse, Responder};
    use futures::{Future, future};

    #[get("/test")]
    pub fn test() -> impl Responder {
        HttpResponse::Ok()
    }

    #[get("/test_async")]
    pub fn auto_sync() -> impl Future<Item=HttpResponse, Error=actix_web::Error> {
        future::ok(HttpResponse::Ok().finish())
    }

    ///Special function to initialize scope. Called as hook before routes registration.
    pub fn init<P: 'static>(scope: actix_web::Scope<P>) -> actix_web::Scope<P> {
        scope
    }

    pub fn default_resource<P: 'static>(res: actix_web::Resource<P>) -> actix_web::Resource<P> {
        res.to(|| HttpResponse::InternalServerError())
    }

};

Note

Internally the macro generate struct with name of scope (e.g. mod_inner) And create public module as <name>_scope