use std::sync::Arc;
use crate::actix_web::{web, Error as ActixError, HttpRequest, HttpResponse};
use crate::futures::Future;
use crate::rest_api::actix_web_1::{Continuation, Method, RequestGuard};
#[cfg(feature = "authorization")]
use crate::rest_api::auth::authorization::Permission;
use super::Service;
pub type Handler = Arc<
dyn Fn(
HttpRequest,
web::Payload,
&dyn Service,
) -> Box<dyn Future<Item = HttpResponse, Error = ActixError>>
+ Send
+ Sync
+ 'static,
>;
pub struct ServiceEndpoint {
pub service_type: String,
pub route: String,
pub method: Method,
pub handler: Handler,
pub request_guards: Vec<Box<dyn ServiceRequestGuard>>,
#[cfg(feature = "authorization")]
pub permission: Permission,
}
pub trait ServiceRequestGuard: RequestGuard {
fn clone_box(&self) -> Box<dyn ServiceRequestGuard>;
}
impl<R> ServiceRequestGuard for R
where
R: RequestGuard + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn ServiceRequestGuard> {
Box::new(self.clone())
}
}
impl Clone for Box<dyn ServiceRequestGuard> {
fn clone(&self) -> Self {
self.clone_box()
}
}
impl RequestGuard for Box<dyn ServiceRequestGuard> {
fn evaluate(&self, req: &HttpRequest) -> Continuation {
(**self).evaluate(req)
}
}