Skip to content

Commit 9fc8cc2

Browse files
Remove Topbar type and replace it with RustdocPage
1 parent 29d2f7c commit 9fc8cc2

File tree

3 files changed

+19
-50
lines changed

3 files changed

+19
-50
lines changed

src/utils/html.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::web::page::templates::{Body, Head, Topbar, Vendored};
2-
use crate::web::rustdoc::RustdocPage;
1+
use crate::web::page::templates::{Body, Head, RustdocPage, Vendored};
32
use lol_html::element;
43
use lol_html::errors::RewritingError;
54
use rinja::Template;
@@ -21,7 +20,7 @@ pub(crate) fn rewrite_lol(
2120
let head_html = Head::new(data).render().unwrap();
2221
let vendored_html = Vendored.render().unwrap();
2322
let body_html = Body.render().unwrap();
24-
let topbar_html = Topbar::new(data).render().unwrap();
23+
let topbar_html = data.render().unwrap();
2524

2625
// Before: <body> ... rustdoc content ... </body>
2726
// After:

src/web/page/templates.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use crate::error::Result;
22
use crate::web::crate_details::CrateDetails;
3-
use crate::web::rustdoc::RustdocPage;
43
use crate::web::MetaData;
54
use anyhow::Context;
65
use rinja::Template;
7-
use std::{fmt, ops::Deref, sync::Arc};
6+
use std::{fmt, sync::Arc};
87
use tracing::trace;
98

109
#[derive(Template)]
@@ -31,34 +30,20 @@ pub struct Body;
3130

3231
#[derive(Template)]
3332
#[template(path = "rustdoc/topbar.html")]
34-
pub struct Topbar<'a> {
35-
inner: &'a RustdocPage,
36-
permalink_path: &'a str,
37-
krate: &'a CrateDetails,
38-
metadata: &'a MetaData,
39-
current_target: &'a str,
40-
latest_path: &'a str,
41-
}
42-
43-
impl<'a> Topbar<'a> {
44-
pub fn new(inner: &'a RustdocPage) -> Self {
45-
Self {
46-
inner,
47-
permalink_path: &inner.permalink_path,
48-
krate: &inner.krate,
49-
metadata: &inner.metadata,
50-
current_target: &inner.current_target,
51-
latest_path: &inner.latest_path,
52-
}
53-
}
54-
}
55-
56-
impl<'a> Deref for Topbar<'a> {
57-
type Target = RustdocPage;
58-
59-
fn deref(&self) -> &Self::Target {
60-
self.inner
61-
}
33+
#[derive(Debug, Clone)]
34+
pub struct RustdocPage {
35+
pub latest_path: String,
36+
pub permalink_path: String,
37+
pub inner_path: String,
38+
// true if we are displaying the latest version of the crate, regardless
39+
// of whether the URL specifies a version number or the string "latest."
40+
pub is_latest_version: bool,
41+
// true if the URL specifies a version using the string "latest."
42+
pub is_latest_url: bool,
43+
pub is_prerelease: bool,
44+
pub krate: CrateDetails,
45+
pub metadata: MetaData,
46+
pub current_target: String,
6247
}
6348

6449
/// Holds all data relevant to templating

src/web/rustdoc.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use crate::{
1414
extractors::{DbConnection, Path},
1515
file::File,
1616
match_version,
17+
page::templates::RustdocPage,
1718
page::TemplateData,
18-
MetaData, ReqVersion,
19+
ReqVersion,
1920
},
2021
AsyncStorage, Config, InstanceMetrics, RUSTDOC_STATIC_STORAGE_PREFIX,
2122
};
@@ -257,22 +258,6 @@ pub(crate) async fn rustdoc_redirector_handler(
257258
}
258259
}
259260

260-
#[derive(Debug, Clone)]
261-
pub struct RustdocPage {
262-
pub latest_path: String,
263-
pub permalink_path: String,
264-
pub inner_path: String,
265-
// true if we are displaying the latest version of the crate, regardless
266-
// of whether the URL specifies a version number or the string "latest."
267-
pub is_latest_version: bool,
268-
// true if the URL specifies a version using the string "latest."
269-
pub is_latest_url: bool,
270-
pub is_prerelease: bool,
271-
pub krate: CrateDetails,
272-
pub metadata: MetaData,
273-
pub current_target: String,
274-
}
275-
276261
impl RustdocPage {
277262
fn into_response(
278263
self,

0 commit comments

Comments
 (0)