use std::sync::Arc;
use http::Method;
use crate::{EndpointFn, Request};
pub trait HttpEndpoint: Sized + Sync + Send + 'static {
type Routes: AsRef<[Method]> + Send;
type Url: AsRef<str>;
type EndpointFn: for<'a> EndpointFn<'a>;
fn register(&mut self) -> (Self::Url, Self::Routes);
fn handler(&self, req: Request) -> <Self::EndpointFn as EndpointFn<'_>>::Fut;
}
pub struct Endpoint<TEndpoint>
where
TEndpoint: HttpEndpoint,
{
pub endpoint: TEndpoint,
}
impl<TEndpoint> Endpoint<TEndpoint>
where
TEndpoint: HttpEndpoint,
{
pub fn from_endpoint(endpoint: TEndpoint) -> Self {
Endpoint { endpoint }
}
pub fn arced(self) -> Arc<Self> {
Arc::new(self)
}
}