diff --git a/utoipa-redoc/src/actix.rs b/utoipa-redoc/src/actix.rs index 0d0be082..53a0fdbd 100644 --- a/utoipa-redoc/src/actix.rs +++ b/utoipa-redoc/src/actix.rs @@ -7,7 +7,7 @@ use actix_web::{HttpResponse, Resource, Responder}; use crate::{Redoc, Spec}; -impl<'s, 'u, S: Spec> HttpServiceFactory for Redoc<'s, 'u, S> { +impl HttpServiceFactory for Redoc { fn register(self, config: &mut actix_web::dev::AppService) { let html = self.to_html(); @@ -17,7 +17,7 @@ impl<'s, 'u, S: Spec> HttpServiceFactory for Redoc<'s, 'u, S> { .body(redoc.to_string()) } - Resource::new(self.url) + Resource::new(self.url.as_ref()) .guard(Get()) .app_data(Data::new(html)) .to(serve_redoc) diff --git a/utoipa-redoc/src/axum.rs b/utoipa-redoc/src/axum.rs index 9c0cb6d3..6f42cf3b 100644 --- a/utoipa-redoc/src/axum.rs +++ b/utoipa-redoc/src/axum.rs @@ -5,13 +5,15 @@ use axum::{routing, Router}; use crate::{Redoc, Spec}; -impl<'s, 'u, S: Spec, R> From> for Router +impl From> for Router where R: Clone + Send + Sync + 'static, - 's: 'static, { - fn from(value: Redoc<'s, 'u, S>) -> Self { + fn from(value: Redoc) -> Self { let html = value.to_html(); - Router::::new().route(value.url, routing::get(move || async { Html(html) })) + Router::::new().route( + value.url.as_ref(), + routing::get(move || async { Html(html) }), + ) } } diff --git a/utoipa-redoc/src/lib.rs b/utoipa-redoc/src/lib.rs index 19c775b7..a4f1c229 100644 --- a/utoipa-redoc/src/lib.rs +++ b/utoipa-redoc/src/lib.rs @@ -181,8 +181,8 @@ //! [redoc_config]: //! [examples]: -use std::env; use std::fs::OpenOptions; +use std::{borrow::Cow, env}; use serde::Serialize; use serde_json::{json, Value}; @@ -206,7 +206,7 @@ const DEFAULT_HTML: &str = include_str!("../res/redoc.html"); doc_cfg, doc(cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))) )] -pub trait Servable<'u, 's, S> +pub trait Servable where S: Spec, { @@ -214,36 +214,34 @@ where /// /// * **url** Must point to location where the [`Servable`] is served. /// * **openapi** Is [`Spec`] that is served via this [`Servable`] from the _**url**_. - fn with_url(url: &'u str, openapi: S) -> Self - where - 'u: 's; + fn with_url>>(url: U, openapi: S) -> Self; /// Construct a new [`Servable`] instance of _`openapi`_ with given _`url`_ and _`config`_. /// /// * **url** Must point to location where the [`Servable`] is served. /// * **openapi** Is [`Spec`] that is served via this [`Servable`] from the _**url**_. /// * **config** Is custom [`Config`] that is used to configure the [`Servable`]. - fn with_url_and_config(url: &'u str, openapi: S, config: C) -> Self - where - 'u: 's; + fn with_url_and_config>, C: Config>( + url: U, + openapi: S, + config: C, + ) -> Self; } #[cfg(any(feature = "actix-web", feature = "rocket", feature = "axum"))] -impl<'u, 's, S: Spec> Servable<'u, 's, S> for Redoc<'u, 's, S> { - fn with_url(url: &'u str, openapi: S) -> Self - where - 'u: 's, - { +impl Servable for Redoc { + fn with_url>>(url: U, openapi: S) -> Self { Self::with_url_and_config(url, openapi, EmptyConfig) } - fn with_url_and_config(url: &'u str, openapi: S, config: C) -> Self - where - 'u: 's, - { + fn with_url_and_config>, C: Config>( + url: U, + openapi: S, + config: C, + ) -> Self { Self { - url, - html: DEFAULT_HTML, + url: url.into(), + html: Cow::Borrowed(DEFAULT_HTML), openapi, config: config.load(), } @@ -259,15 +257,15 @@ impl<'u, 's, S: Spec> Servable<'u, 's, S> for Redoc<'u, 's, S> { /// [redoc]: #[non_exhaustive] #[derive(Clone)] -pub struct Redoc<'s, 'u, S: Spec> { +pub struct Redoc { #[allow(unused)] - url: &'u str, - html: &'s str, + url: Cow<'static, str>, + html: Cow<'static, str>, openapi: S, config: Value, } -impl<'s, 'u, S: Spec> Redoc<'s, 'u, S> { +impl Redoc { /// Constructs a new [`Redoc`] instance for given _`openapi`_ [`Spec`]. /// /// This will create [`Redoc`] with [`EmptyConfig`]. @@ -296,8 +294,8 @@ impl<'s, 'u, S: Spec> Redoc<'s, 'u, S> { /// ``` pub fn with_config(openapi: S, config: C) -> Self { Self { - html: DEFAULT_HTML, - url: "", + html: Cow::Borrowed(DEFAULT_HTML), + url: Cow::Borrowed(""), openapi, config: config.load(), } @@ -308,8 +306,8 @@ impl<'s, 'u, S: Spec> Redoc<'s, 'u, S> { /// /// [redoc_html_quickstart]: /// [customization]: index.html#customization - pub fn custom_html(mut self, html: &'s str) -> Self { - self.html = html; + pub fn custom_html>>(mut self, html: H) -> Self { + self.html = html.into(); self } diff --git a/utoipa-redoc/src/rocket.rs b/utoipa-redoc/src/rocket.rs index a350a9e5..1609d4a4 100644 --- a/utoipa-redoc/src/rocket.rs +++ b/utoipa-redoc/src/rocket.rs @@ -7,11 +7,11 @@ use rocket::{Data, Request, Route}; use crate::{Redoc, Spec}; -impl<'s, 'u, S: Spec> From> for Vec { - fn from(value: Redoc<'s, 'u, S>) -> Self { +impl From> for Vec { + fn from(value: Redoc) -> Self { vec![Route::new( Method::Get, - value.url, + value.url.as_ref(), RedocHandler(value.to_html()), )] }