From 9bd6d0d308059025e0fa80ffa360d779687e97fa Mon Sep 17 00:00:00 2001 From: Jakob Dalsgaard Date: Mon, 30 Dec 2024 12:48:58 +0100 Subject: [PATCH 1/2] Introducing feature 'alloc' that removes dependency of alloc::sync::Arc --- maud/Cargo.toml | 1 + maud/src/lib.rs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/maud/Cargo.toml b/maud/Cargo.toml index 419f95bf..83b6a759 100644 --- a/maud/Cargo.toml +++ b/maud/Cargo.toml @@ -14,6 +14,7 @@ edition.workspace = true [features] default = [] +alloc = [] # Web framework integrations actix-web = ["actix-web-dep", "futures-util"] diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 7647379c..5971f23c 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -11,7 +11,11 @@ extern crate alloc; -use alloc::{borrow::Cow, boxed::Box, string::String, sync::Arc}; +use alloc::{borrow::Cow, boxed::Box, string::String}; + +#[cfg(not(feature = "alloc"))] +use alloc::sync::Arc; + use core::fmt::{self, Arguments, Display, Write}; pub use maud_macros::html; @@ -150,6 +154,7 @@ impl Render for Box { } } +#[cfg(not(feature = "alloc"))] impl Render for Arc { fn render_to(&self, w: &mut String) { T::render_to(self, w); From 5208bd3cffa8d685242787d2ee50d8aec5b70287 Mon Sep 17 00:00:00 2001 From: Jakob Dalsgaard Date: Mon, 14 Apr 2025 10:37:42 +0200 Subject: [PATCH 2/2] Picoserve addon --- maud/Cargo.toml | 2 ++ maud/src/lib.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/maud/Cargo.toml b/maud/Cargo.toml index 83b6a759..6cce6e7c 100644 --- a/maud/Cargo.toml +++ b/maud/Cargo.toml @@ -15,6 +15,7 @@ edition.workspace = true [features] default = [] alloc = [] +picoserve = ["dep:picoserve"] # Web framework integrations actix-web = ["actix-web-dep", "futures-util"] @@ -31,6 +32,7 @@ axum-core = { version = "0.4", optional = true } submillisecond = { version = "0.4.1", optional = true } http = { version = "1", optional = true } warp = { version = "0.3.6", optional = true } +picoserve = { version = ">=0.13.3", optional = true } [dev-dependencies] trybuild = { version = "1.0.33", features = ["diff"] } diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 5971f23c..5bdb70a2 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -383,6 +383,26 @@ mod axum_support { } } +#[cfg(feature = "picoserve")] +mod picoserve_support { + use crate::Markup; + use picoserve::{response::{Content}, io::Write}; + + impl Content for Markup { + fn content_type(&self) -> &'static str { + "text/html; charset=utf-8" + } + + fn content_length(&self) -> usize { + self.0.len() + } + + async fn write_content(self, writer: W) -> Result<(), W::Error> { + self.0.clone().write_content(writer).await + } + } +} + #[cfg(feature = "warp")] mod warp_support { use crate::PreEscaped;