Skip to content

Commit

Permalink
Remove AsRef<str> restriction from structs (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
imbolc authored May 28, 2023
1 parent ca7b93c commit 1ab01cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

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

## [0.25.0] - 2023-04-16

- Remove `html_debug!`
Expand Down
2 changes: 1 addition & 1 deletion docs/content/render-trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use maud::{Markup, PreEscaped, Render};
use pulldown_cmark::{Parser, html};

/// Renders a block of Markdown using `pulldown-cmark`.
struct Markdown<T: AsRef<str>>(T);
struct Markdown<T>(T);

impl<T: AsRef<str>> Render for Markdown<T> {
fn render(&self) -> Markup {
Expand Down
8 changes: 4 additions & 4 deletions maud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pub fn display(value: impl Display) -> impl Render {

/// A wrapper that renders the inner value without escaping.
#[derive(Debug, Clone, Copy)]
pub struct PreEscaped<T: AsRef<str>>(pub T);
pub struct PreEscaped<T>(pub T);

impl<T: AsRef<str>> Render for PreEscaped<T> {
fn render_to(&self, w: &mut String) {
Expand All @@ -228,20 +228,20 @@ impl<T: AsRef<str>> Render for PreEscaped<T> {
/// The `html!` macro expands to an expression of this type.
pub type Markup = PreEscaped<String>;

impl<T: AsRef<str> + Into<String>> PreEscaped<T> {
impl<T: Into<String>> PreEscaped<T> {
/// Converts the inner value to a string.
pub fn into_string(self) -> String {
self.0.into()
}
}

impl<T: AsRef<str> + Into<String>> From<PreEscaped<T>> for String {
impl<T: Into<String>> From<PreEscaped<T>> for String {
fn from(value: PreEscaped<T>) -> String {
value.into_string()
}
}

impl<T: AsRef<str> + Default> Default for PreEscaped<T> {
impl<T: Default> Default for PreEscaped<T> {
fn default() -> Self {
Self(Default::default())
}
Expand Down

0 comments on commit 1ab01cc

Please sign in to comment.