Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl Render for Arc<Render> #380

Merged
merged 3 commits into from
May 28, 2023
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Remove `AsRef<str>` restriction from `PreEscaped`
[#377](https://github.com/lambda-fairy/maud/pull/377)
- Implement `Render` for `Arc<T>`
[#380](https://github.com/lambda-fairy/maud/pull/380)

## [0.25.0] - 2023-04-16

Expand Down
8 changes: 7 additions & 1 deletion maud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

extern crate alloc;

use alloc::{borrow::Cow, boxed::Box, string::String};
use alloc::{borrow::Cow, boxed::Box, string::String, sync::Arc};
use core::fmt::{self, Arguments, Display, Write};

pub use maud_macros::html;
Expand Down Expand Up @@ -150,6 +150,12 @@ impl<T: Render + ?Sized> Render for Box<T> {
}
}

impl<T: Render + ?Sized> Render for Arc<T> {
fn render_to(&self, w: &mut String) {
T::render_to(self, w);
}
}

macro_rules! impl_render_with_display {
($($ty:ty)*) => {
$(
Expand Down
6 changes: 6 additions & 0 deletions maud/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,9 @@ fn default() {
assert_eq!(Markup::default().0, "");
assert_eq!(PreEscaped::<&'static str>::default().0, "");
}

#[test]
fn render_arc() {
let arc = std::sync::Arc::new("foo");
assert_eq!(html! { (arc) }.into_string(), "foo");
}