From 0de60b0c8615b1ba7fe7f47f324281a4255456de Mon Sep 17 00:00:00 2001 From: Paul Jones <1019888+SenojLuap@users.noreply.github.com> Date: Sat, 30 Dec 2023 04:10:30 -0500 Subject: [PATCH] Update rocket support to v0.5 (#406) * update rocket support to v0.5 * added rocket upgrade to CHANGELOG.md * fix documentation code for rocket v0.5 --------- Co-authored-by: Chris Wong --- CHANGELOG.md | 2 ++ docs/content/web-frameworks.md | 9 ++++----- doctest/Cargo.toml | 2 +- maud/Cargo.toml | 2 +- maud/src/lib.rs | 8 ++++---- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e5f58f9..69b4df92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ [#396](https://github.com/lambda-fairy/maud/pull/396) - Support `axum` v0.7 through `axum-core` v0.4 and `http` v1 [#401](https://github.com/lambda-fairy/maud/pull/401) +- Support `rocket` v0.5 + [#406](https://github.com/lambda-fairy/maud/pull/406) ## [0.25.0] - 2023-04-16 diff --git a/docs/content/web-frameworks.md b/docs/content/web-frameworks.md index c81bf5a6..b5442a56 100644 --- a/docs/content/web-frameworks.md +++ b/docs/content/web-frameworks.md @@ -60,22 +60,21 @@ maud = { version = "*", features = ["rocket"] } This adds a `Responder` implementation for the `Markup` type, so you can return the result directly: ```rust,no_run -#![feature(decl_macro)] - use maud::{html, Markup}; use rocket::{get, routes}; use std::borrow::Cow; #[get("/")] -fn hello<'a>(name: Cow<'a, str>) -> Markup { +fn hello(name: &str) -> Markup { html! { h1 { "Hello, " (name) "!" } p { "Nice to meet you!" } } } -fn main() { - rocket::ignite().mount("/", routes![hello]).launch(); +#[rocket::launch] +fn launch() -> _ { + rocket::build().mount("/", routes![hello]) } ``` diff --git a/doctest/Cargo.toml b/doctest/Cargo.toml index ee2794c4..9f479436 100644 --- a/doctest/Cargo.toml +++ b/doctest/Cargo.toml @@ -9,7 +9,7 @@ actix-web = { version = "4.0.0-rc.2", default-features = false, features = ["mac ammonia = "3" maud = { path = "../maud", features = ["actix-web", "rocket", "tide", "axum"] } pulldown-cmark = "0.8" -rocket = "0.4" +rocket = "0.5" rouille = "3" tide = "0.16" tokio = { version = "1.9.0", features = ["rt", "macros", "rt-multi-thread"] } diff --git a/maud/Cargo.toml b/maud/Cargo.toml index 16d9a9b8..d4b61ca4 100644 --- a/maud/Cargo.toml +++ b/maud/Cargo.toml @@ -21,7 +21,7 @@ axum = ["axum-core", "http"] [dependencies] maud_macros = { version = "0.25.0", path = "../maud_macros" } itoa = "1" -rocket = { version = ">= 0.3, < 0.5", optional = true } +rocket = { version = "0.5", optional = true } futures-util = { version = "0.3.0", optional = true, default-features = false } actix-web-dep = { package = "actix-web", version = "4", optional = true, default-features = false } tide = { version = "0.16.0", optional = true, default-features = false } diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 02de568c..d6b45b7f 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -284,17 +284,17 @@ mod rocket_support { use crate::PreEscaped; use alloc::string::String; use rocket::{ - http::{ContentType, Status}, + http::ContentType, request::Request, response::{Responder, Response}, }; use std::io::Cursor; - impl Responder<'static> for PreEscaped { - fn respond_to(self, _: &Request) -> Result, Status> { + impl<'r> Responder<'r, 'static> for PreEscaped { + fn respond_to(self, _: &Request) -> rocket::response::Result<'static> { Response::build() .header(ContentType::HTML) - .sized_body(Cursor::new(self.0)) + .sized_body(self.0.len(), Cursor::new(self.0)) .ok() } }