Get rid of lifetime on Service

This commit is contained in:
Brian Picciano 2023-06-18 15:10:06 +02:00
parent 1f9ae0038f
commit 7ea97b2617
2 changed files with 8 additions and 8 deletions

View File

@ -14,20 +14,20 @@ use crate::{domain, origin, service};
type SvcResponse = Result<Response<hyper::body::Body>, String>; type SvcResponse = Result<Response<hyper::body::Body>, String>;
#[derive(Clone)] #[derive(Clone)]
pub struct Service<'svc> { pub struct Service {
domain_manager: sync::Arc<dyn domain::manager::Manager>, domain_manager: sync::Arc<dyn domain::manager::Manager>,
target_a: net::Ipv4Addr, target_a: net::Ipv4Addr,
passphrase: String, passphrase: String,
http_domain: domain::Name, http_domain: domain::Name,
handlebars: handlebars::Handlebars<'svc>, handlebars: handlebars::Handlebars<'static>,
} }
pub fn new<'svc>( pub fn new(
domain_manager: sync::Arc<dyn domain::manager::Manager>, domain_manager: sync::Arc<dyn domain::manager::Manager>,
target_a: net::Ipv4Addr, target_a: net::Ipv4Addr,
passphrase: String, passphrase: String,
http_domain: domain::Name, http_domain: domain::Name,
) -> Service<'svc> { ) -> Service {
Service { Service {
domain_manager, domain_manager,
target_a, target_a,
@ -59,7 +59,7 @@ struct DomainSyncArgs {
passphrase: String, passphrase: String,
} }
impl<'svc> Service<'svc> { impl<'svc> Service {
fn serve_string(&self, status_code: u16, path: &'_ str, body: Vec<u8>) -> SvcResponse { fn serve_string(&self, status_code: u16, path: &'_ str, body: Vec<u8>) -> SvcResponse {
let content_type = mime_guess::from_path(path) let content_type = mime_guess::from_path(path)
.first_or_octet_stream() .first_or_octet_stream()
@ -307,7 +307,7 @@ impl<'svc> Service<'svc> {
} }
pub async fn handle_request( pub async fn handle_request(
svc: sync::Arc<Service<'_>>, svc: sync::Arc<Service>,
req: Request<Body>, req: Request<Body>,
) -> Result<Response<Body>, Infallible> { ) -> Result<Response<Body>, Infallible> {
match handle_request_inner(svc, req).await { match handle_request_inner(svc, req).await {
@ -323,7 +323,7 @@ fn strip_port(host: &str) -> &str {
} }
} }
pub async fn handle_request_inner(svc: sync::Arc<Service<'_>>, req: Request<Body>) -> SvcResponse { pub async fn handle_request_inner(svc: sync::Arc<Service>, req: Request<Body>) -> SvcResponse {
let maybe_host = match ( let maybe_host = match (
req.headers() req.headers()
.get("Host") .get("Host")

View File

@ -5,7 +5,7 @@ use handlebars::Handlebars;
#[prefix = "/"] #[prefix = "/"]
struct Dir; struct Dir;
pub fn get<'hbs>() -> Handlebars<'hbs> { pub fn get() -> Handlebars<'static> {
let mut reg = Handlebars::new(); let mut reg = Handlebars::new();
reg.register_embed_templates::<Dir>() reg.register_embed_templates::<Dir>()
.expect("registered embedded templates"); .expect("registered embedded templates");