}
}
-#[derive(Debug)]
-enum Setting {
- Section {
- description: &'static str,
- sub_settings: Vec<Setting>,
- },
- Toggle {
- js_data_name: &'static str,
- description: &'static str,
- default_value: bool,
- },
- Select {
- js_data_name: &'static str,
- description: &'static str,
- default_value: &'static str,
- options: Vec<String>,
- },
-}
-
-impl Setting {
- fn display(&self, root_path: &str, suffix: &str) -> String {
- match *self {
- Setting::Section { description, ref sub_settings } => format!(
- "<div class=\"setting-line\">\
- <div class=\"title\">{}</div>\
- <div class=\"sub-settings\">{}</div>
- </div>",
- description,
- sub_settings.iter().map(|s| s.display(root_path, suffix)).collect::<String>()
- ),
- Setting::Toggle { js_data_name, description, default_value } => format!(
- "<div class=\"setting-line\">\
- <label class=\"toggle\">\
- <input type=\"checkbox\" id=\"{}\" {}>\
- <span class=\"slider\"></span>\
- </label>\
- <div>{}</div>\
- </div>",
- js_data_name,
- if default_value { " checked" } else { "" },
- description,
- ),
- Setting::Select { js_data_name, description, default_value, ref options } => format!(
- "<div class=\"setting-line\"><div class=\"radio-line\" id=\"{}\"><span class=\"setting-name\">{}</span><div class=\"choices\">{}</div></div></div>",
- js_data_name,
- description,
- options
- .iter()
- .map(|opt| format!(
- "<label for=\"{js_data_name}-{name}\" class=\"choice\">
- <input type=\"radio\" name=\"{js_data_name}\" id=\"{js_data_name}-{name}\" value=\"{name}\" {checked}>\
- {name}\
- </label>",
- js_data_name = js_data_name,
- name = opt,
- checked = if opt == default_value { "checked" } else { "" },
- ))
- .collect::<String>(),
- ),
- }
- }
-}
-
-impl From<(&'static str, &'static str, bool)> for Setting {
- fn from(values: (&'static str, &'static str, bool)) -> Setting {
- Setting::Toggle { js_data_name: values.0, description: values.1, default_value: values.2 }
- }
-}
-
-impl<T: Into<Setting>> From<(&'static str, Vec<T>)> for Setting {
- fn from(values: (&'static str, Vec<T>)) -> Setting {
- Setting::Section {
- description: values.0,
- sub_settings: values.1.into_iter().map(|v| v.into()).collect::<Vec<_>>(),
- }
- }
-}
-
-fn settings(root_path: &str, suffix: &str, theme_names: Vec<String>) -> Result<String, Error> {
- // (id, explanation, default value)
- let settings: &[Setting] = &[
- Setting::from(("use-system-theme", "Use system theme", true)),
- Setting::Select {
- js_data_name: "theme",
- description: "Theme",
- default_value: "light",
- options: theme_names.clone(),
- },
- Setting::Select {
- js_data_name: "preferred-light-theme",
- description: "Preferred light theme",
- default_value: "light",
- options: theme_names.clone(),
- },
- Setting::Select {
- js_data_name: "preferred-dark-theme",
- description: "Preferred dark theme",
- default_value: "dark",
- options: theme_names,
- },
- ("auto-hide-large-items", "Auto-hide item contents for large items.", true).into(),
- ("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
- ("auto-hide-trait-implementations", "Auto-hide trait implementation documentation", false)
- .into(),
- ("go-to-only-result", "Directly go to item in search if there is only one result", false)
- .into(),
- ("line-numbers", "Show line numbers on code examples", false).into(),
- ("disable-shortcuts", "Disable keyboard shortcuts", false).into(),
- ];
-
- Ok(format!(
- "<div class=\"main-heading\">
- <h1 class=\"fqn\">\
- <span class=\"in-band\">Rustdoc settings</span>\
- </h1>\
- <span class=\"out-of-band\">\
- <a id=\"back\" href=\"javascript:void(0)\">Back</a>\
- </span>\
- </div>\
- <div class=\"settings\">{}</div>\
- <link rel=\"stylesheet\" href=\"{root_path}settings{suffix}.css\">\
- <script src=\"{root_path}settings{suffix}.js\"></script>",
- settings.iter().map(|s| s.display(root_path, suffix)).collect::<String>(),
- root_path = root_path,
- suffix = suffix
- ))
-}
-
fn scrape_examples_help(shared: &SharedContext<'_>) -> String {
let mut content = SCRAPE_EXAMPLES_HELP_MD.to_owned();
content.push_str(&format!(
w,
"{extra}{vis}const <a{href} class=\"constant\">{name}</a>: {ty}",
extra = extra,
- vis = it.visibility.print_with_space(it.def_id, cx),
+ vis = it.visibility.print_with_space(it.item_id, cx),
href = assoc_href_attr(it, link, cx),
name = it.name.as_ref().unwrap(),
ty = ty.print(cx),
) {
let header = meth.fn_header(cx.tcx()).expect("Trying to get header from a non-function item");
let name = meth.name.as_ref().unwrap();
- let vis = meth.visibility.print_with_space(meth.def_id, cx).to_string();
+ let vis = meth.visibility.print_with_space(meth.item_id, cx).to_string();
// FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove
// this condition.
let constness = match render_mode {
}
fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
- let did = it.def_id.expect_def_id();
+ let did = it.item_id.expect_def_id();
let cache = cx.cache();
if let Some(v) = cache.impls.get(&did) {
);
let cache = cx.cache();
- if let Some(implementors) = cache.implementors.get(&it.def_id.expect_def_id()) {
+ if let Some(implementors) = cache.implementors.get(&it.item_id.expect_def_id()) {
let mut res = implementors
.iter()
.filter(|i| {
let item_sections_in_use: FxHashSet<_> = items
.iter()
- .filter(|it| !it.is_stripped() && it.name.is_some())
+ .filter(|it| {
+ !it.is_stripped()
+ && it
+ .name
+ .or_else(|| {
+ if let clean::ImportItem(ref i) = *it.kind &&
+ let clean::ImportKind::Simple(s) = i.kind { Some(s) } else { None }
+ })
+ .is_some()
+ })
.map(|it| item_ty_to_section(it.type_()))
.collect();
for &sec in ItemSection::ALL.iter().filter(|sec| item_sections_in_use.contains(sec)) {
/// Generates the HTML for example call locations generated via the --scrape-examples flag.
fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
let tcx = cx.tcx();
- let def_id = item.def_id.expect_def_id();
+ let def_id = item.item_id.expect_def_id();
let key = tcx.def_path_hash(def_id);
let Some(call_locations) = cx.shared.call_locations.get(&key) else { return };