Skip to content

Commit e0e0c37

Browse files
Replace SlashChecker with ensure_trailing_slash
1 parent aa4055c commit e0e0c37

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/librustdoc/html/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use crate::externalfiles::ExternalHtml;
4-
use crate::html::render::SlashChecker;
4+
use crate::html::render::ensure_trailing_slash;
55
use crate::html::format::{Buffer, Print};
66

77
#[derive(Clone)]
@@ -180,7 +180,7 @@ pub fn render<T: Print, S: Print>(
180180
css_class = page.css_class,
181181
logo = {
182182
let p = format!("{}{}", page.root_path, layout.krate);
183-
let p = SlashChecker(&p);
183+
let p = ensure_trailing_slash(&p);
184184
if layout.logo.is_empty() {
185185
format!("<a href='{path}index.html'>\
186186
<div class='logo-container'>\

src/librustdoc/html/render.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use std::cmp::Ordering;
3333
use std::collections::{BTreeMap, VecDeque};
3434
use std::default::Default;
3535
use std::error;
36-
use std::fmt::{self, Display, Formatter, Write as FmtWrite};
36+
use std::fmt::{self, Formatter, Write as FmtWrite};
3737
use std::ffi::OsStr;
3838
use std::fs::{self, File};
3939
use std::io::prelude::*;
@@ -82,16 +82,14 @@ mod tests;
8282
/// A pair of name and its optional document.
8383
pub type NameDoc = (String, Option<String>);
8484

85-
pub struct SlashChecker<'a>(pub &'a str);
86-
87-
impl<'a> Display for SlashChecker<'a> {
88-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
89-
if !self.0.ends_with("/") && !self.0.is_empty() {
90-
write!(f, "{}/", self.0)
85+
crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
86+
crate::html::format::display_fn(move |f| {
87+
if !v.ends_with("/") && !v.is_empty() {
88+
write!(f, "{}/", v)
9189
} else {
92-
write!(f, "{}", self.0)
90+
write!(f, "{}", v)
9391
}
94-
}
92+
})
9593
}
9694

9795
#[derive(Debug)]
@@ -106,7 +104,7 @@ impl error::Error for Error {
106104
}
107105
}
108106

109-
impl Display for Error {
107+
impl std::fmt::Display for Error {
110108
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
111109
let file = self.file.display().to_string();
112110
if file.is_empty() {
@@ -1162,7 +1160,7 @@ themePicker.onblur = handleThemeButtonsBlur;
11621160
.iter()
11631161
.map(|s| {
11641162
format!("<li><a href=\"{}index.html\">{}</li>",
1165-
SlashChecker(s), s)
1163+
ensure_trailing_slash(s), s)
11661164
})
11671165
.collect::<String>());
11681166
let v = layout::render(&cx.shared.layout,
@@ -2286,7 +2284,7 @@ fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer) {
22862284

22872285
fn item_path(ty: ItemType, name: &str) -> String {
22882286
match ty {
2289-
ItemType::Module => format!("{}index.html", SlashChecker(name)),
2287+
ItemType::Module => format!("{}index.html", ensure_trailing_slash(name)),
22902288
_ => format!("{}.{}.html", ty, name),
22912289
}
22922290
}

0 commit comments

Comments
 (0)