lambda-fairy / maud

:pencil: Compile-time HTML templates for Rust
https://maud.lambda.xyz
Apache License 2.0
2.14k stars 143 forks source link

Added: Render for Option<T> #447

Open re-oh opened 1 month ago

re-oh commented 1 month ago
impl<T: Render + ?Sized> Render for Option<T> {
    fn render_to(&self, w: &mut String) { if let Some(inner) = self { T::render_to(inner, w); } }
}

impl <T: Render + ?Sized, I: ExactSizeIterator + ?Sized> Render for I where I::Item: AsRef<T> {
    fn render_to(&self, w: &mut String) {
        for item in self {
            item.as_ref().render_to(w);
        }
    }
}

Implemented Render for 2 types:

If there are any suggestions for other types to implement or if my implementation has issues ill gladly fix them.

re-oh commented 1 month ago

Also removed the ?Sized bound on T for Option<T> since Apparently Option<T> needs for T to be sized.

re-oh commented 1 month ago

closes issue / feature request: #446