-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rustdoc: Add ItemTemplate
trait and related functions to avoid repetitively wrapping existing functions
#111946
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 just thought about something: could we instead of calling
.borrow()
change the API ofitem_template_render_assoc_items
to take a&RefCell<T> where T: ItemTemplate
or something equivalent to not have to write.borrow()
every time? I'm not sure if it's possible though. If you could confirm it, it'd be awesome!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.
self::item_template_render_attributes_in_pre(self) | safe
expands to.borrow()
:&::askama::filters::safe(::askama::Html, self::item_template_render_attributes_in_pre(&(self)))?
.borrow()
:&::askama::filters::safe(::askama::Html, self::item_template_render_attributes_in_pre({self.borrow()}))?
I'm not sure why the function didn't catch
&(self)
as&impl ItemTemplate
, butself.borrow()
does here (self.borrow()
returns&ItemUnion
) ...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 found out that we can remove
.borrow()
calls by:ItemTemplate
trait for&ItemUnion
.borrow()
askama::Template
trait for&ItemUnion
askama::Template
for&T
Template
is from an external crate (not sure if we should make a feature request for this to be available)T
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'm pretty much stuck at this point, what do you think? @GuillaumeGomez
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 really like the first suggestion which also seems to be the simplest to be implemented (but maybe I'm wrong there). Thanks for taking a look! So what do you prefer: making the changes here directly or opening an issue and fixing it in a follow-up PR?
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.
Oops, I laid them out wrongly, they should be implemented together.
Doing only the 1st item will cause errors, and the compiler suggested to do the 2nd item to fix it.
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.
Oh I see. Well, that still seems doable. Then same question for how you prefer things to roll out. :)
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.
Nevertheless, I'd prefer to do a follow-up PR and open up a new issue. I would like to see opinions from others (in case there exists something simpler).
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 go this way then! I r+ this PR. Please open an issue. ;)