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

Add missing impls for AsIdent + fix impl for Pin<?Sized> #125

Merged
merged 1 commit into from
Aug 9, 2024
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
11 changes: 2 additions & 9 deletions rinja/src/filters/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl<T: HtmlSafe + ?Sized> HtmlSafe for Box<T> {}
impl<T: HtmlSafe + ?Sized> HtmlSafe for std::cell::Ref<'_, T> {}
impl<T: HtmlSafe + ?Sized> HtmlSafe for std::cell::RefMut<'_, T> {}
impl<T: HtmlSafe + ?Sized> HtmlSafe for std::rc::Rc<T> {}
impl<T: HtmlSafe + ?Sized> HtmlSafe for std::pin::Pin<&T> {}
impl<T: HtmlSafe + ?Sized> HtmlSafe for std::sync::Arc<T> {}
impl<T: HtmlSafe + ?Sized> HtmlSafe for std::sync::MutexGuard<'_, T> {}
impl<T: HtmlSafe + ?Sized> HtmlSafe for std::sync::RwLockReadGuard<'_, T> {}
Expand All @@ -418,8 +419,6 @@ where
{
}

impl<T: HtmlSafe> HtmlSafe for std::pin::Pin<&T> {}

/// Used internally by rinja to select the appropriate [`write!()`] mechanism
pub struct Writable<'a, S: ?Sized>(pub &'a S);

Expand Down Expand Up @@ -454,6 +453,7 @@ const _: () = {
Box<T>
std::cell::Ref<'_, T>
std::cell::RefMut<'_, T>
std::pin::Pin<&T>
std::rc::Rc<T>
std::sync::Arc<T>
std::sync::MutexGuard<'_, T>
Expand All @@ -468,13 +468,6 @@ const _: () = {
}
}

impl<T: FastWritable> FastWritable for std::pin::Pin<&T> {
#[inline]
fn write_into<W: fmt::Write + ?Sized>(&self, dest: &mut W) -> fmt::Result {
T::write_into(self, dest)
}
}

// implement FastWritable for a list of types
macro_rules! impl_for_int {
($($ty:ty)*) => { $(
Expand Down
52 changes: 25 additions & 27 deletions rinja/src/filters/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,39 +84,37 @@ impl AsIndent for usize {
}
}

impl<T: AsIndent + ?Sized> AsIndent for &T {
#[inline]
fn as_indent(&self) -> &str {
T::as_indent(self)
}
}

impl<T: AsIndent + ?Sized> AsIndent for Box<T> {
#[inline]
fn as_indent(&self) -> &str {
T::as_indent(self.as_ref())
}
}

impl<T: AsIndent + ToOwned + ?Sized> AsIndent for std::borrow::Cow<'_, T> {
#[inline]
fn as_indent(&self) -> &str {
T::as_indent(self.as_ref())
}
}

impl<T: AsIndent + ?Sized> AsIndent for std::rc::Rc<T> {
#[inline]
fn as_indent(&self) -> &str {
T::as_indent(self.as_ref())
T::as_indent(self)
}
}

impl<T: AsIndent + ?Sized> AsIndent for std::sync::Arc<T> {
#[inline]
fn as_indent(&self) -> &str {
T::as_indent(self.as_ref())
}
// implement AsIdent for a list of reference wrapper types to AsIdent
macro_rules! impl_as_ident_for_ref {
($T:ident => $($ty:ty)*) => { $(
impl<T: AsIndent + ?Sized> AsIndent for $ty {
#[inline]
fn as_indent(&self) -> &str {
<T>::as_indent(self)
}
}
)* };
}

impl_as_ident_for_ref! {
T =>
&T
Box<T>
std::cell::Ref<'_, T>
std::cell::RefMut<'_, T>
std::pin::Pin<&T>
std::rc::Rc<T>
std::sync::Arc<T>
std::sync::MutexGuard<'_, T>
std::sync::RwLockReadGuard<'_, T>
std::sync::RwLockWriteGuard<'_, T>
}

impl<S: Serialize> fmt::Display for ToJson<S> {
Expand Down