-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Generic type bounds are not handled #38
Comments
This is something the derive macro doesn't handle yet. The correct use, I believe, would be: #[derive(ramhorns::Content)]
struct SamplePage {
username: String,
age: u64,
}
#[derive(ramhorns::Content)]
struct PageWithMetadata<T> { // no trait bounds here
#[ramhorns(flatten)]
page: T,
metadata: (),
} The derive macro would then have to conditionally |
That makes sense. I can try and put together a pull request for that, if that would be helpful? |
I'm more than happy to accept a PR for this :). The generics are currently only copied dumbly into the output stream currently. This works with lifetimes, but obviously breaks here, so that's the part needs to be more robust. Field rendering should work fine without changes I believe. |
I have a use-case where I would like to wrap the content for individual pages with a generic "page + metadata" content struct (e.g. to provide i18n, script information, etc).
However, this fails with a series of fairly-indecipherable errors:
Reading briefly through the source, it seems like the generic part is not being parsed or broken down further, and simply being quoted in when necessary, which works for simple type parameters (e.g.
<T>
) but not when there are bounds on those types.I also tried this by using a
where T: ramhorns::Content
block:Is this supported at all/is there an obvious alternative way to achieve this? My other way of solving this would be by putting the metadata inside the
SamplePage
struct, but this involves more repetition and messy APIs, so I was hoping to avoid this.Thanks!
The text was updated successfully, but these errors were encountered: