Skip to content

Commit 8829b11

Browse files
committed
Make all dist functions and structs crate-private and cleanup unused functions
Signed-off-by: hi-rustin <[email protected]>
1 parent 08972a6 commit 8829b11

17 files changed

+122
-133
lines changed

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::env;
22

33
include!("src/dist/triple.rs");
44

5-
pub fn from_build() -> Result<PartialTargetTriple, String> {
5+
fn from_build() -> Result<PartialTargetTriple, String> {
66
let triple = if let Ok(triple) = env::var("RUSTUP_OVERRIDE_BUILD_TRIPLE") {
77
triple
88
} else {

src/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl Display for PgpPublicKey {
229229
pub const UNIX_FALLBACK_SETTINGS: &str = "/etc/rustup/settings.toml";
230230

231231
pub struct Cfg {
232-
pub profile_override: Option<dist::Profile>,
232+
profile_override: Option<dist::Profile>,
233233
pub rustup_dir: PathBuf,
234234
pub settings_file: SettingsFile,
235235
pub fallback_settings: Option<FallbackSettings>,
@@ -376,7 +376,7 @@ impl Cfg {
376376
&self.pgp_keys
377377
}
378378

379-
pub fn set_profile_override(&mut self, profile: dist::Profile) {
379+
pub(crate) fn set_profile_override(&mut self, profile: dist::Profile) {
380380
self.profile_override = Some(profile);
381381
}
382382

@@ -429,7 +429,7 @@ impl Cfg {
429429
// if there is no profile in the settings file. The last variant happens when
430430
// a user upgrades from a version of Rustup without profiles to a version of
431431
// Rustup with profiles.
432-
pub fn get_profile(&self) -> Result<dist::Profile> {
432+
pub(crate) fn get_profile(&self) -> Result<dist::Profile> {
433433
if let Some(p) = self.profile_override {
434434
return Ok(p);
435435
}
@@ -986,7 +986,7 @@ impl Cfg {
986986
})
987987
}
988988

989-
pub fn get_default_host_triple(&self) -> Result<dist::TargetTriple> {
989+
pub(crate) fn get_default_host_triple(&self) -> Result<dist::TargetTriple> {
990990
Ok(self
991991
.settings_file
992992
.with(|s| {

src/dist/component/components.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Components {
7373
})
7474
.collect())
7575
}
76-
pub fn add<'a>(&self, name: &str, tx: Transaction<'a>) -> ComponentBuilder<'a> {
76+
pub(crate) fn add<'a>(&self, name: &str, tx: Transaction<'a>) -> ComponentBuilder<'a> {
7777
ComponentBuilder {
7878
components: self.clone(),
7979
name: name.to_owned(),
@@ -85,40 +85,40 @@ impl Components {
8585
let result = self.list()?;
8686
Ok(result.into_iter().find(|c| (c.name() == name)))
8787
}
88-
pub fn prefix(&self) -> InstallPrefix {
88+
pub(crate) fn prefix(&self) -> InstallPrefix {
8989
self.prefix.clone()
9090
}
9191
}
9292

93-
pub struct ComponentBuilder<'a> {
93+
pub(crate) struct ComponentBuilder<'a> {
9494
components: Components,
9595
name: String,
9696
parts: Vec<ComponentPart>,
9797
tx: Transaction<'a>,
9898
}
9999

100100
impl<'a> ComponentBuilder<'a> {
101-
pub fn copy_file(&mut self, path: PathBuf, src: &Path) -> Result<()> {
101+
pub(crate) fn copy_file(&mut self, path: PathBuf, src: &Path) -> Result<()> {
102102
self.parts
103103
.push(ComponentPart("file".to_owned(), path.clone()));
104104
self.tx.copy_file(&self.name, path, src)
105105
}
106-
pub fn copy_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> {
106+
pub(crate) fn copy_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> {
107107
self.parts
108108
.push(ComponentPart("dir".to_owned(), path.clone()));
109109
self.tx.copy_dir(&self.name, path, src)
110110
}
111-
pub fn move_file(&mut self, path: PathBuf, src: &Path) -> Result<()> {
111+
pub(crate) fn move_file(&mut self, path: PathBuf, src: &Path) -> Result<()> {
112112
self.parts
113113
.push(ComponentPart("file".to_owned(), path.clone()));
114114
self.tx.move_file(&self.name, path, src)
115115
}
116-
pub fn move_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> {
116+
pub(crate) fn move_dir(&mut self, path: PathBuf, src: &Path) -> Result<()> {
117117
self.parts
118118
.push(ComponentPart("dir".to_owned(), path.clone()));
119119
self.tx.move_dir(&self.name, path, src)
120120
}
121-
pub fn finish(mut self) -> Result<Transaction<'a>> {
121+
pub(crate) fn finish(mut self) -> Result<Transaction<'a>> {
122122
// Write component manifest
123123
let path = self.components.rel_component_manifest(&self.name);
124124
let abs_path = self.components.prefix.abs_path(&path);
@@ -143,13 +143,13 @@ impl<'a> ComponentBuilder<'a> {
143143
}
144144

145145
#[derive(Debug)]
146-
pub struct ComponentPart(pub String, pub PathBuf);
146+
pub(crate) struct ComponentPart(pub(crate) String, pub(crate) PathBuf);
147147

148148
impl ComponentPart {
149-
pub fn encode(&self) -> String {
149+
pub(crate) fn encode(&self) -> String {
150150
format!("{}:{}", &self.0, &self.1.to_string_lossy())
151151
}
152-
pub fn decode(line: &str) -> Option<Self> {
152+
pub(crate) fn decode(line: &str) -> Option<Self> {
153153
line.find(':')
154154
.map(|pos| Self(line[0..pos].to_owned(), PathBuf::from(&line[(pos + 1)..])))
155155
}
@@ -162,21 +162,21 @@ pub struct Component {
162162
}
163163

164164
impl Component {
165-
pub fn manifest_name(&self) -> String {
165+
pub(crate) fn manifest_name(&self) -> String {
166166
format!("manifest-{}", &self.name)
167167
}
168-
pub fn manifest_file(&self) -> PathBuf {
168+
pub(crate) fn manifest_file(&self) -> PathBuf {
169169
self.components.prefix.manifest_file(&self.manifest_name())
170170
}
171-
pub fn rel_manifest_file(&self) -> PathBuf {
171+
pub(crate) fn rel_manifest_file(&self) -> PathBuf {
172172
self.components
173173
.prefix
174174
.rel_manifest_file(&self.manifest_name())
175175
}
176-
pub fn name(&self) -> &str {
176+
pub(crate) fn name(&self) -> &str {
177177
&self.name
178178
}
179-
pub fn parts(&self) -> Result<Vec<ComponentPart>> {
179+
pub(crate) fn parts(&self) -> Result<Vec<ComponentPart>> {
180180
let mut result = Vec::new();
181181
for line in utils::read_file("component", &self.manifest_file())?.lines() {
182182
result.push(

src/dist/component/package.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::utils::notifications::Notification;
2121
use crate::utils::utils;
2222

2323
/// The current metadata revision used by rust-installer
24-
pub const INSTALLER_VERSION: &str = "3";
25-
pub const VERSION_FILE: &str = "rust-installer-version";
24+
pub(crate) const INSTALLER_VERSION: &str = "3";
25+
pub(crate) const VERSION_FILE: &str = "rust-installer-version";
2626

2727
pub trait Package: fmt::Debug {
2828
fn contains(&self, component: &str, short_name: Option<&str>) -> bool;
@@ -136,7 +136,7 @@ impl Package for DirectoryPackage {
136136
}
137137

138138
#[derive(Debug)]
139-
pub struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>);
139+
pub(crate) struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>);
140140

141141
impl<'a> TarPackage<'a> {
142142
pub(crate) fn new<R: Read>(
@@ -548,7 +548,7 @@ impl<'a> Package for TarPackage<'a> {
548548
}
549549

550550
#[derive(Debug)]
551-
pub struct TarGzPackage<'a>(TarPackage<'a>);
551+
pub(crate) struct TarGzPackage<'a>(TarPackage<'a>);
552552

553553
impl<'a> TarGzPackage<'a> {
554554
pub(crate) fn new<R: Read>(
@@ -584,7 +584,7 @@ impl<'a> Package for TarGzPackage<'a> {
584584
}
585585

586586
#[derive(Debug)]
587-
pub struct TarXzPackage<'a>(TarPackage<'a>);
587+
pub(crate) struct TarXzPackage<'a>(TarPackage<'a>);
588588

589589
impl<'a> TarXzPackage<'a> {
590590
pub(crate) fn new<R: Read>(
@@ -620,7 +620,7 @@ impl<'a> Package for TarXzPackage<'a> {
620620
}
621621

622622
#[derive(Debug)]
623-
pub struct TarZStdPackage<'a>(TarPackage<'a>);
623+
pub(crate) struct TarZStdPackage<'a>(TarPackage<'a>);
624624

625625
impl<'a> TarZStdPackage<'a> {
626626
pub(crate) fn new<R: Read>(

src/dist/component/transaction.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ impl<'a> Transaction<'a> {
148148
}
149149

150150
/// Move a file to a relative path of the install prefix.
151-
pub fn move_file(&mut self, component: &str, relpath: PathBuf, src: &Path) -> Result<()> {
151+
pub(crate) fn move_file(
152+
&mut self,
153+
component: &str,
154+
relpath: PathBuf,
155+
src: &Path,
156+
) -> Result<()> {
152157
assert!(relpath.is_relative());
153158
let item =
154159
ChangedItem::move_file(&self.prefix, component, relpath, src, self.notify_handler())?;
@@ -157,15 +162,15 @@ impl<'a> Transaction<'a> {
157162
}
158163

159164
/// Recursively move a directory to a relative path of the install prefix.
160-
pub fn move_dir(&mut self, component: &str, relpath: PathBuf, src: &Path) -> Result<()> {
165+
pub(crate) fn move_dir(&mut self, component: &str, relpath: PathBuf, src: &Path) -> Result<()> {
161166
assert!(relpath.is_relative());
162167
let item =
163168
ChangedItem::move_dir(&self.prefix, component, relpath, src, self.notify_handler())?;
164169
self.change(item);
165170
Ok(())
166171
}
167172

168-
pub fn temp(&self) -> &'a temp::Cfg {
173+
pub(crate) fn temp(&self) -> &'a temp::Cfg {
169174
self.temp_cfg
170175
}
171176
pub(crate) fn notify_handler(&self) -> &'a dyn Fn(Notification<'_>) {

src/dist/config.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use super::manifest::Component;
44
use crate::errors::*;
55
use crate::utils::toml_utils::*;
66

7-
pub const SUPPORTED_CONFIG_VERSIONS: [&str; 1] = ["1"];
8-
pub const DEFAULT_CONFIG_VERSION: &str = "1";
7+
pub(crate) const SUPPORTED_CONFIG_VERSIONS: [&str; 1] = ["1"];
8+
pub(crate) const DEFAULT_CONFIG_VERSION: &str = "1";
99

1010
#[derive(Clone, Debug)]
1111
pub struct Config {
@@ -14,7 +14,7 @@ pub struct Config {
1414
}
1515

1616
impl Config {
17-
pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result<Self> {
17+
pub(crate) fn from_toml(mut table: toml::value::Table, path: &str) -> Result<Self> {
1818
let config_version = get_string(&mut table, "config_version", path)?;
1919
if !SUPPORTED_CONFIG_VERSIONS.contains(&&*config_version) {
2020
bail!(RustupError::UnsupportedVersion(config_version));
@@ -29,7 +29,7 @@ impl Config {
2929
components,
3030
})
3131
}
32-
pub fn into_toml(self) -> toml::value::Table {
32+
pub(crate) fn into_toml(self) -> toml::value::Table {
3333
let mut result = toml::value::Table::new();
3434
result.insert(
3535
"config_version".to_owned(),
@@ -42,12 +42,12 @@ impl Config {
4242
result
4343
}
4444

45-
pub fn parse(data: &str) -> Result<Self> {
45+
pub(crate) fn parse(data: &str) -> Result<Self> {
4646
let value = toml::from_str(data).context("error parsing manifest")?;
4747
Self::from_toml(value, "")
4848
}
4949

50-
pub fn stringify(self) -> String {
50+
pub(crate) fn stringify(self) -> String {
5151
toml::Value::Table(self.into_toml()).to_string()
5252
}
5353

@@ -72,7 +72,7 @@ impl Config {
7272
result
7373
}
7474

75-
pub fn new() -> Self {
75+
pub(crate) fn new() -> Self {
7676
Default::default()
7777
}
7878
}

0 commit comments

Comments
 (0)