Show value for consts in the documentation
This commit is contained in:
parent
625375400c
commit
811bdeee00
11 changed files with 192 additions and 16 deletions
|
@ -2272,14 +2272,36 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
|
|||
fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Constant) {
|
||||
write!(w, "<pre class='rust const'>");
|
||||
render_attributes(w, it, false);
|
||||
|
||||
write!(
|
||||
w,
|
||||
"{vis}const \
|
||||
{name}: {typ}</pre>",
|
||||
{name}: {typ}",
|
||||
vis = it.visibility.print_with_space(),
|
||||
name = it.name.as_ref().unwrap(),
|
||||
typ = c.type_.print()
|
||||
typ = c.type_.print(),
|
||||
);
|
||||
|
||||
if c.value.is_some() || c.is_literal {
|
||||
write!(w, " = {expr};", expr = c.expr);
|
||||
} else {
|
||||
write!(w, ";");
|
||||
}
|
||||
|
||||
if let Some(value) = &c.value {
|
||||
if !c.is_literal {
|
||||
let value_lowercase = value.to_lowercase();
|
||||
let expr_lowercase = c.expr.to_lowercase();
|
||||
|
||||
if value_lowercase != expr_lowercase
|
||||
&& value_lowercase.trim_end_matches("i32") != expr_lowercase
|
||||
{
|
||||
write!(w, " // {value}", value = value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
write!(w, "</pre>");
|
||||
document(w, cx, it)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue