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

Remove AsRef<str> restriction from structs #377

Merged
merged 2 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
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