-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Moved no-receiver size_hint method to a separate trait #270
Conversation
In this one, why isn't |
Yes. I could move that into the other trait too (and rename the new trait) if desired. |
(and in that case the Sized bound would no longer be needed) |
So as an alternative, could we add a |
It works, but you have to also add a |
askama/src/lib.rs
Outdated
fn dyn_size_hint(&self) -> usize; | ||
} | ||
|
||
pub trait TemplateSizeHint { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this to SizedTemplate
and move both extension()
and size_hint()
into it?
askama/src/lib.rs
Outdated
@@ -502,6 +502,10 @@ pub trait Template { | |||
fn extension() -> Option<&'static str> | |||
where | |||
Self: Sized; | |||
fn dyn_size_hint(&self) -> usize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say maybe we can just name this size_hint()
for now? Not sure if the conflict causes issues in the common case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they have the same name then importing SizedTemplate
and trying to use the receiverless size_hint()
will give a "multiple applicable items in scope" compile error if Template
is also imported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think I'm okay with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it basically make the receiverless size_hint()
unusable? Or is there a way to disambiguate?
(Giving extension()
the same treatment causes the same compile error in testing/tests/simple.rs
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do something like SizedTemplate::extension(&t)
or <t as SizedTemplate>::extension()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, it works. I've updated the PR.
Thanks for sticking with it and working through this with me! |
(Also, I'd be curious to hear a little bit more about what you're using Askama for.) |
No description provided.