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

Rendering enum of templates #130

Open
rhelmot opened this issue Aug 10, 2023 · 1 comment
Open

Rendering enum of templates #130

rhelmot opened this issue Aug 10, 2023 · 1 comment

Comments

@rhelmot
Copy link

rhelmot commented Aug 10, 2023

Let's say I have the following pattern:

#[derive(TemplateOnce)]
#[template(path = "index.stpl")]
struct Index {
    page: Page,
}

enum Page {
    Index(PageHome),
    Stream(PageStream),
}

#[derive(TemplateOnce)]
#[template(path = "pages/home.stpl")]
struct PageHome {
    ...
}

#[derive(TemplateOnce)]
#[template(path = "pages/stream.stpl")]
struct PageStream {
    ...
}

What can I write in the template such that I am able to render page? As far as I can tell, I can't implement TemplateOnce for Page since it has a sealed supertrait, and I can't implement Render for it since in order to render the child I would have to consume its value. I additionally can't change page to be dyn TemplateOnce since TemplateOnce is Sized.

What's the best way to dispatch to different templates?

@PaulDotSH
Copy link
Contributor

I think this can be done with a macro, if you still need this I'm open to try to create one @rhelmot

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

No branches or pull requests

2 participants