Repository: lambda-fairy/maud
Pull request #371 (2023-03-24 10:16:10)

impl Default for PreEscaped
Tests was broken before the change, I'm not sure if I should fix them. But `cargo test misc` works.

imbolc: Also I noticed seemingly unnecessary type restriction: 
`struct PreEscaped<T: AsRef<str>>(pub T)`. I believe removing the `AsRef` restriction won't change any behavior, but it won't be necessary to repeat the restriction in each implementation. I can remove it in this PR if you'd like.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93c665d..351bbc7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@
   [#357](https://github.com/lambda-fairy/maud/pull/357)
 - Support `axum` v0.6 through `axum-core` v0.3
   [#361](https://github.com/lambda-fairy/maud/pull/361)
+- Implement `Default` for `PreEscaped`
+  [#371](https://github.com/lambda-fairy/maud/pull/371)
 
 ## [0.24.0] - 2022-08-12
 
diff --git a/docs/content/render-trait.md b/docs/content/render-trait.md
index cae04bb..2f536ff 100644
--- a/docs/content/render-trait.md
+++ b/docs/content/render-trait.md
@@ -1,7 +1,8 @@
 # The `Render` trait
 
-Maud uses the [`Render`][Render] trait to convert [`(spliced)`](splices-toggles.md) values to HTML.
-This is implemented for many Rust primitive types (`&str`, `i32`) by default, but you can implement it for your own types as well.
+For most types, Maud will use the [`std::fmt::Display`][Display] trait to convert [`(spliced)`](splices-toggles.md) values to HTML.
+(The result will be escaped automatically.)
+If you'd like to override this behavior for your own type, then you can implement the [`Render`][Render] trait instead.
 
 Below are some examples of implementing `Render`.
 Feel free to use these snippets in your own project!
diff --git a/docs/content/web-frameworks.md b/docs/content/web-frameworks.md
index ce0d676..3579f1a 100644
--- a/docs/content/web-frameworks.md
+++ b/docs/content/web-frameworks.md
@@ -1,11 +1,12 @@
 # Web framework integration
 
-Maud includes support for these web frameworks: [Actix], [Rocket], [Rouille], and [Tide].
+Maud includes support for these web frameworks: [Actix], [Rocket], [Rouille], [Tide] and [Axum].
 
 [Actix]: https://actix.rs/
 [Rocket]: https://rocket.rs/
 [Rouille]: https://github.com/tomaka/rouille
 [Tide]: https://docs.rs/tide/
+[Axum]: https://docs.rs/axum/
 
 # Actix
 
diff --git a/docs/src/lib.rs b/docs/src/lib.rs
index ac61d5b..0d2c6ba 100644
--- a/docs/src/lib.rs
+++ b/docs/src/lib.rs
@@ -1,4 +1,4 @@
-#![feature(once_cell)]
+#![feature(lazy_cell)]
 
 pub mod page;
 pub mod string_writer;
diff --git a/maud/src/lib.rs b/maud/src/lib.rs
index 9c4a180..800098b 100644
--- a/maud/src/lib.rs
+++ b/maud/src/lib.rs
@@ -241,6 +241,12 @@ impl<T: AsRef<str> + Into<String>> From<PreEscaped<T>> for String {
     }
 }
 
+impl<T: AsRef<str> + Default> Default for PreEscaped<T> {
+    fn default() -> Self {
+        Self(Default::default())
+    }
+}
+
 /// The literal string `<!DOCTYPE html>`.
 ///
 /// # Example


Test patch:
diff --git a/maud/tests/misc.rs b/maud/tests/misc.rs
index b9aae52..4f6752b 100644
--- a/maud/tests/misc.rs
+++ b/maud/tests/misc.rs
@@ -130,3 +130,10 @@ fn prefer_render_over_display() {
         "&lt;display&gt;"
     );
 }
+
+#[test]
+fn default() {
+    use maud::{Markup, PreEscaped};
+    assert_eq!(Markup::default().0, "");
+    assert_eq!(PreEscaped::<&'static str>::default().0, "");
+}