Skip to content

rustdoc: migrate item_keyword to an askama template #111314

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,24 @@ fn item_foreign_type(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
}

fn item_keyword(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))
#[derive(Template)]
#[template(path = "item_keyword.html")]
struct ItemKeyword<'a, 'cx> {
cx: std::cell::RefCell<&'a mut Context<'cx>>,
it: &'a clean::Item,
}

impl<'a, 'cx: 'a> ItemKeyword<'a, 'cx> {
fn document<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
display_fn(move |f| {
let mut cx = self.cx.borrow_mut();
let v = document(*cx, self.it, None, HeadingOffset::H2);
write!(f, "{v}")
})
}
}

ItemKeyword { cx: std::cell::RefCell::new(cx), it }.render_into(w).unwrap();
}

/// Compare two strings treating multi-digit numbers as single units (i.e. natural sort order).
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/templates/item_keyword.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ self.document() | safe }}