Add support for tuple structs' fields documentation
This commit is contained in:
parent
478126c0f3
commit
ec76b6eedd
2 changed files with 12 additions and 9 deletions
|
@ -2007,6 +2007,9 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea
|
|||
}
|
||||
|
||||
sidebar.push_str("</div>");
|
||||
} else if let CtorKind::Fn = s.struct_type {
|
||||
sidebar
|
||||
.push_str("<h3 class=\"sidebar-title\"><a href=\"#fields\">Tuple Fields</a></h3>");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1176,21 +1176,21 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
|
|||
_ => None,
|
||||
})
|
||||
.peekable();
|
||||
if let CtorKind::Fictive = s.struct_type {
|
||||
if let CtorKind::Fictive | CtorKind::Fn = s.struct_type {
|
||||
if fields.peek().is_some() {
|
||||
write!(
|
||||
w,
|
||||
"<h2 id=\"fields\" class=\"fields small-section-header\">\
|
||||
Fields{}<a href=\"#fields\" class=\"anchor\"></a></h2>",
|
||||
{}{}<a href=\"#fields\" class=\"anchor\"></a>\
|
||||
</h2>",
|
||||
if let CtorKind::Fictive = s.struct_type { "Fields" } else { "Tuple Fields" },
|
||||
document_non_exhaustive_header(it)
|
||||
);
|
||||
document_non_exhaustive(w, it);
|
||||
for (field, ty) in fields {
|
||||
let id = cx.derive_id(format!(
|
||||
"{}.{}",
|
||||
ItemType::StructField,
|
||||
field.name.as_ref().unwrap()
|
||||
));
|
||||
for (index, (field, ty)) in fields.enumerate() {
|
||||
let field_name =
|
||||
field.name.map_or_else(|| index.to_string(), |sym| (*sym.as_str()).to_string());
|
||||
let id = cx.derive_id(format!("{}.{}", ItemType::StructField, field_name));
|
||||
write!(
|
||||
w,
|
||||
"<span id=\"{id}\" class=\"{item_type} small-section-header\">\
|
||||
|
@ -1199,7 +1199,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
|
|||
</span>",
|
||||
item_type = ItemType::StructField,
|
||||
id = id,
|
||||
name = field.name.as_ref().unwrap(),
|
||||
name = field_name,
|
||||
ty = ty.print(cx)
|
||||
);
|
||||
document(w, cx, field, Some(it));
|
||||
|
|
Loading…
Reference in a new issue