#[derive(Scope)]
{
// Attributes available to this derive:
#[path]
#[service]
#[guard]
}
Expand description
Generates Application
Similar to scope macro
ยงExample
use futures::{Future, future};
use actix_web_cute_codegen::{get, scope, Scope};
#[get("/test")]
fn test() -> impl actix_web::Responder {
actix_web::HttpResponse::Ok()
}
#[derive(Scope)]
#[path="/my_scope"]
pub struct MyScope {
#[service]
test: test,
#[guard]
guard: actix_web::guard::AnyGuard,
}
#[scope]
impl MyScope {
fn new() -> Self {
Self {
test: test,
guard: actix_web::guard::Any(actix_web::guard::Get()).or(actix_web::guard::Post()),
}
}
//Special member to act as hook
pub fn init<P: 'static>(scope: actix_web::Scope<P>) -> actix_web::Scope<P> {
scope
}
//Mark any function as initialization of scope
#[hook]
pub fn init_scope<P: 'static>(scope: actix_web::Scope<P>) -> actix_web::Scope<P> {
scope
}
pub fn init_scope_unused<P: 'static>(scope: actix_web::Scope<P>) -> actix_web::Scope<P> {
scope
}
#[get("/test_async")]
pub fn test_async() -> impl Future<Item=actix_web::HttpResponse, Error=actix_web::Error> {
future::ok(actix_web::HttpResponse::Ok().finish())
}
pub fn default_resource<P: 'static>(res: actix_web::Resource<P>) -> actix_web::Resource<P> {
res.to(|| actix_web::HttpResponse::InternalServerError())
}
}