Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions maud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ edition.workspace = true

[features]
default = []
alloc = []
picoserve = ["dep:picoserve"]

# Web framework integrations
actix-web = ["actix-web-dep", "futures-util"]
Expand All @@ -30,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"] }
Expand Down
27 changes: 26 additions & 1 deletion maud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,6 +154,7 @@ impl<T: Render + ?Sized> Render for Box<T> {
}
}

#[cfg(not(feature = "alloc"))]
impl<T: Render + ?Sized> Render for Arc<T> {
fn render_to(&self, w: &mut String) {
T::render_to(self, w);
Expand Down Expand Up @@ -378,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<W: Write>(self, writer: W) -> Result<(), W::Error> {
self.0.clone().write_content(writer).await
}
}
}

#[cfg(feature = "warp")]
mod warp_support {
use crate::PreEscaped;
Expand Down