Skip to content

Commit 1dc6c87

Browse files
committed
use const instead of static
also uses a constant instead of hardcoding the default target
1 parent fa14994 commit 1dc6c87

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/db/add_package.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub(crate) fn add_package_into_database(conn: &Connection,
2626
metadata_pkg: &MetadataPackage,
2727
source_dir: &Path,
2828
res: &BuildResult,
29+
default_target: &str,
2930
files: Option<Json>,
3031
doc_targets: Vec<String>,
3132
cratesio_data: &CratesIoData,
@@ -82,7 +83,7 @@ pub(crate) fn add_package_into_database(conn: &Connection,
8283
&is_library,
8384
&res.rustc_version,
8485
&metadata_pkg.documentation,
85-
&res.target])?;
86+
&default_target])?;
8687
// return id
8788
rows.get(0).get(0)
8889

@@ -136,7 +137,7 @@ pub(crate) fn add_package_into_database(conn: &Connection,
136137
&is_library,
137138
&res.rustc_version,
138139
&metadata_pkg.documentation,
139-
&res.target])?;
140+
&default_target])?;
140141
rows.get(0).get(0)
141142
}
142143
};

src/docbuilder/rustwide_builder.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ use std::path::Path;
1818
use utils::{copy_doc_dir, parse_rustc_version, CargoMetadata};
1919
use Metadata;
2020

21-
static USER_AGENT: &str = "docs.rs builder (https://github.com/rust-lang/docs.rs)";
22-
static DEFAULT_RUSTWIDE_WORKSPACE: &str = ".rustwide";
21+
const USER_AGENT: &str = "docs.rs builder (https://github.com/rust-lang/docs.rs)";
22+
const DEFAULT_RUSTWIDE_WORKSPACE: &str = ".rustwide";
2323

24-
static TARGETS: &[&str] = &[
24+
const DEFAULT_TARGET: &str = "x86_64-unknown-linux-gnu";
25+
const TARGETS: &[&str] = &[
2526
"i686-pc-windows-msvc",
2627
"i686-unknown-linux-gnu",
2728
"x86_64-apple-darwin",
2829
"x86_64-pc-windows-msvc",
2930
"x86_64-unknown-linux-gnu",
3031
];
3132

32-
static ESSENTIAL_FILES_VERSIONED: &[&str] = &[
33+
const ESSENTIAL_FILES_VERSIONED: &[&str] = &[
3334
"brush.svg",
3435
"wheel.svg",
3536
"down-arrow.svg",
@@ -46,7 +47,7 @@ static ESSENTIAL_FILES_VERSIONED: &[&str] = &[
4647
"noscript.css",
4748
"rust-logo.png",
4849
];
49-
static ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
50+
const ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
5051
"FiraSans-Medium.woff",
5152
"FiraSans-Regular.woff",
5253
"SourceCodePro-Regular.woff",
@@ -56,8 +57,8 @@ static ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
5657
"SourceSerifPro-It.ttf.woff",
5758
];
5859

59-
static DUMMY_CRATE_NAME: &str = "acme-client";
60-
static DUMMY_CRATE_VERSION: &str = "0.0.0";
60+
const DUMMY_CRATE_NAME: &str = "acme-client";
61+
const DUMMY_CRATE_VERSION: &str = "0.0.0";
6162

6263
pub struct RustwideBuilder {
6364
workspace: Workspace,
@@ -363,6 +364,7 @@ impl RustwideBuilder {
363364
res.cargo_metadata.root(),
364365
&build.host_source_dir(),
365366
&res.result,
367+
&res.target,
366368
files_list,
367369
successful_targets,
368370
&CratesIoData::get_from_network(res.cargo_metadata.root())?,
@@ -481,8 +483,7 @@ impl RustwideBuilder {
481483
successful,
482484
},
483485
cargo_metadata,
484-
target: target.unwrap_or("x86_64-unknown-linux-gnu").to_string(),
485-
default_target: metadata.default_target.clone(),
486+
target: target.unwrap_or(DEFAULT_TARGET).to_string(),
486487
})
487488
}
488489

@@ -530,7 +531,6 @@ impl RustwideBuilder {
530531
struct FullBuildResult {
531532
result: BuildResult,
532533
target: String,
533-
default_target: Option<String>,
534534
cargo_metadata: CargoMetadata,
535535
}
536536

@@ -539,5 +539,4 @@ pub(crate) struct BuildResult {
539539
pub(crate) docsrs_version: String,
540540
pub(crate) build_log: String,
541541
pub(crate) successful: bool,
542-
pub(crate) target: String,
543542
}

src/test/fakes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl<'db> FakeRelease<'db> {
8484
&self.package,
8585
tempdir.path(),
8686
&self.build_result,
87+
&self.default_target.unwrap_or("x86_64-unknown-linux-gnu"),
8788
self.files,
8889
self.doc_targets,
8990
&self.cratesio_data,

0 commit comments

Comments
 (0)