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

Added: Render for Option<T> #447

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Added: Render for Option<T> #447

wants to merge 2 commits into from

Conversation

re-oh
Copy link

@re-oh re-oh commented Oct 10, 2024

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:

  • ExactSizeIterator since if it was infinite like: 0.. it would run forever. ( Not 100% sure if this implementation works, if anyone could tell me how i can test this it would be much appreciated since you dont need a owned value to render it. ergo AsRef<T> for I::Item)
  • Option<T> Simple, if self is some render the inner value if not, dont render it. ( I think thats how @martinhath wanted it to work. )

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

@re-oh
Copy link
Author

re-oh commented Oct 10, 2024

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

@re-oh re-oh changed the title Added: Render for Option<T> & ExactSizeIterator where I::Item: AsRef<T> Added: Render for Option<T> Oct 10, 2024
@re-oh re-oh changed the title Added: Render for Option<T> Added: Render for Option<T> closes: #446 Oct 10, 2024
@re-oh re-oh changed the title Added: Render for Option<T> closes: #446 Added: Render for Option<T> Oct 10, 2024
@re-oh
Copy link
Author

re-oh commented Oct 10, 2024

closes issue / feature request: #446

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant