Skip to content

Commit

Permalink
Impl Render for Arc<Render> (#380)
Browse files Browse the repository at this point in the history
* Arc

* Changelog
  • Loading branch information
imbolc authored May 28, 2023
1 parent 1ab01cc commit b7e5768
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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");
}

0 comments on commit b7e5768

Please sign in to comment.