Skip to content

Commit

Permalink
Reduce visibility of items that are not publicly accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 16, 2024
1 parent e8dfc24 commit 8562fca
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 57 deletions.
18 changes: 9 additions & 9 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ use std::process::{Command, Output, Stdio};
use std::{env, fs, iter};

#[derive(Deserialize)]
pub struct Metadata {
pub(crate) struct Metadata {
pub target_directory: Directory,
pub workspace_root: Directory,
pub packages: Vec<PackageMetadata>,
}

#[derive(Deserialize)]
pub struct PackageMetadata {
pub(crate) struct PackageMetadata {
pub name: String,
pub targets: Vec<BuildTarget>,
pub manifest_path: PathBuf,
}

#[derive(Deserialize)]
pub struct BuildTarget {
pub(crate) struct BuildTarget {
pub crate_types: Vec<String>,
}

Expand Down Expand Up @@ -51,7 +51,7 @@ fn cargo_target_dir(project: &Project) -> impl Iterator<Item = (&'static str, Pa
))
}

pub fn manifest_dir() -> Result<Directory> {
pub(crate) fn manifest_dir() -> Result<Directory> {
if let Some(manifest_dir) = env::var_os("CARGO_MANIFEST_DIR") {
return Ok(Directory::from(manifest_dir));
}
Expand All @@ -64,7 +64,7 @@ pub fn manifest_dir() -> Result<Directory> {
}
}

pub fn build_dependencies(project: &mut Project) -> Result<()> {
pub(crate) fn build_dependencies(project: &mut Project) -> Result<()> {
let workspace_cargo_lock = path!(project.workspace / "Cargo.lock");
if workspace_cargo_lock.exists() {
let _ = fs::copy(workspace_cargo_lock, path!(project.dir / "Cargo.lock"));
Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn build_dependencies(project: &mut Project) -> Result<()> {
Ok(())
}

pub fn build_test(project: &Project, name: &Name) -> Result<Output> {
pub(crate) fn build_test(project: &Project, name: &Name) -> Result<Output> {
let _ = cargo(project)
.arg("clean")
.arg("--package")
Expand All @@ -120,7 +120,7 @@ pub fn build_test(project: &Project, name: &Name) -> Result<Output> {
.map_err(Error::Cargo)
}

pub fn build_all_tests(project: &Project) -> Result<Output> {
pub(crate) fn build_all_tests(project: &Project) -> Result<Output> {
let _ = cargo(project)
.arg("clean")
.arg("--package")
Expand All @@ -143,7 +143,7 @@ pub fn build_all_tests(project: &Project) -> Result<Output> {
.map_err(Error::Cargo)
}

pub fn run_test(project: &Project, name: &Name) -> Result<Output> {
pub(crate) fn run_test(project: &Project, name: &Name) -> Result<Output> {
cargo(project)
.arg("run")
.args(target())
Expand All @@ -156,7 +156,7 @@ pub fn run_test(project: &Project, name: &Name) -> Result<Output> {
.map_err(Error::Cargo)
}

pub fn metadata() -> Result<Metadata> {
pub(crate) fn metadata() -> Result<Metadata> {
let output = raw_cargo()
.arg("metadata")
.arg("--no-deps")
Expand Down
28 changes: 15 additions & 13 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::fmt;
use std::fs;
use std::path::PathBuf;

pub fn get_manifest(manifest_dir: &Directory) -> Result<Manifest, Error> {
pub(crate) fn get_manifest(manifest_dir: &Directory) -> Result<Manifest, Error> {
let cargo_toml_path = manifest_dir.join("Cargo.toml");
let mut manifest = (|| {
let manifest_str = fs::read_to_string(&cargo_toml_path)?;
Expand All @@ -32,11 +32,13 @@ pub fn get_manifest(manifest_dir: &Directory) -> Result<Manifest, Error> {
Ok(manifest)
}

pub fn get_workspace_manifest(manifest_dir: &Directory) -> WorkspaceManifest {
pub(crate) fn get_workspace_manifest(manifest_dir: &Directory) -> WorkspaceManifest {
try_get_workspace_manifest(manifest_dir).unwrap_or_default()
}

pub fn try_get_workspace_manifest(manifest_dir: &Directory) -> Result<WorkspaceManifest, Error> {
pub(crate) fn try_get_workspace_manifest(
manifest_dir: &Directory,
) -> Result<WorkspaceManifest, Error> {
let cargo_toml_path = manifest_dir.join("Cargo.toml");
let manifest_str = fs::read_to_string(cargo_toml_path)?;
let mut manifest: WorkspaceManifest = basic_toml::from_str(&manifest_str)?;
Expand Down Expand Up @@ -72,7 +74,7 @@ fn fix_replacements(replacements: &mut Map<String, Patch>, dir: &Directory) {
}

#[derive(Deserialize, Default, Debug)]
pub struct WorkspaceManifest {
pub(crate) struct WorkspaceManifest {
#[serde(default)]
pub workspace: WorkspaceWorkspace,
#[serde(default)]
Expand All @@ -82,20 +84,20 @@ pub struct WorkspaceManifest {
}

#[derive(Deserialize, Default, Debug)]
pub struct WorkspaceWorkspace {
pub(crate) struct WorkspaceWorkspace {
#[serde(default)]
pub package: WorkspacePackage,
#[serde(default)]
pub dependencies: Map<String, Dependency>,
}

#[derive(Deserialize, Default, Debug)]
pub struct WorkspacePackage {
pub(crate) struct WorkspacePackage {
pub edition: Option<Edition>,
}

#[derive(Deserialize, Default, Debug)]
pub struct Manifest {
pub(crate) struct Manifest {
#[serde(rename = "cargo-features", default)]
pub cargo_features: Vec<String>,
#[serde(default)]
Expand All @@ -111,22 +113,22 @@ pub struct Manifest {
}

#[derive(Deserialize, Default, Debug)]
pub struct Package {
pub(crate) struct Package {
pub name: String,
#[serde(default)]
pub edition: EditionOrInherit,
pub resolver: Option<String>,
}

#[derive(Debug)]
pub enum EditionOrInherit {
pub(crate) enum EditionOrInherit {
Edition(Edition),
Inherit,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(remote = "Self")]
pub struct Dependency {
pub(crate) struct Dependency {
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -156,7 +158,7 @@ pub struct Dependency {
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct TargetDependencies {
pub(crate) struct TargetDependencies {
#[serde(default, skip_serializing_if = "Map::is_empty")]
pub dependencies: Map<String, Dependency>,
#[serde(
Expand All @@ -169,12 +171,12 @@ pub struct TargetDependencies {

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(transparent)]
pub struct RegistryPatch {
pub(crate) struct RegistryPatch {
pub crates: Map<String, Patch>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Patch {
pub(crate) struct Patch {
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<PathBuf>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
8 changes: 4 additions & 4 deletions src/diff.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use self::r#impl::Diff;
pub(crate) use self::r#impl::Diff;

pub enum Render<'a> {
pub(crate) enum Render<'a> {
Common(&'a str),
Unique(&'a str),
}
Expand All @@ -12,7 +12,7 @@ mod r#impl {
use std::cmp;
use std::panic;

pub struct Diff<'a> {
pub(crate) struct Diff<'a> {
expected: &'a str,
actual: &'a str,
diff: Vec<Chunk<'a>>,
Expand Down Expand Up @@ -66,7 +66,7 @@ mod r#impl {
mod r#impl {
use super::Render;

pub enum Diff {}
pub(crate) enum Diff {}

impl Diff {
pub fn compute(_expected: &str, _actual: &str) -> Option<Self> {
Expand Down
2 changes: 1 addition & 1 deletion src/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::{Path, PathBuf};

#[derive(Clone, Debug, Serialize)]
#[serde(transparent)]
pub struct Directory {
pub(crate) struct Directory {
path: PathBuf,
}

Expand Down
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error::{Error, Result};
use std::env;

#[derive(PartialEq, Debug)]
pub enum Update {
pub(crate) enum Update {
Wip,
Overwrite,
}
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io;
use std::path::PathBuf;

#[derive(Debug)]
pub enum Error {
pub(crate) enum Error {
Cargo(io::Error),
CargoFail,
GetManifest(PathBuf, Box<Error>),
Expand All @@ -25,7 +25,7 @@ pub enum Error {
WriteStderr(io::Error),
}

pub type Result<T> = std::result::Result<T, Error>;
pub(crate) type Result<T> = std::result::Result<T, Error>;

impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::ffi::OsStr;
use std::fs;
use std::path::PathBuf;

pub fn find() -> Option<Vec<String>> {
pub(crate) fn find() -> Option<Vec<String>> {
try_find().ok()
}

Expand Down
2 changes: 1 addition & 1 deletion src/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::time::{Duration, SystemTime};

static LOCK: OnceCell<Mutex<()>> = OnceCell::new();

pub struct Lock {
pub(crate) struct Lock {
intraprocess_guard: Guard,
lockfile: FileLock,
}
Expand Down
5 changes: 3 additions & 2 deletions src/inherit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use std::fmt;

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct InheritEdition {
pub(crate) struct InheritEdition {
#[allow(dead_code)]
pub workspace: True,
}

pub struct True;
pub(crate) struct True;

impl<'de> Deserialize<'de> for True {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand Down
16 changes: 8 additions & 8 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::ffi::OsStr;
use std::path::PathBuf;

#[derive(Serialize, Debug)]
pub struct Manifest {
pub(crate) struct Manifest {
#[serde(rename = "cargo-features", skip_serializing_if = "Vec::is_empty")]
pub cargo_features: Vec<String>,
pub package: Package,
Expand All @@ -29,7 +29,7 @@ pub struct Manifest {
}

#[derive(Serialize, Debug)]
pub struct Package {
pub(crate) struct Package {
pub name: String,
pub version: String,
pub edition: Edition,
Expand All @@ -39,7 +39,7 @@ pub struct Package {
}

#[derive(Serialize, Deserialize, Debug)]
pub enum Edition {
pub(crate) enum Edition {
#[serde(rename = "2015")]
E2015,
#[serde(rename = "2018")]
Expand All @@ -51,26 +51,26 @@ pub enum Edition {
}

#[derive(Serialize, Debug)]
pub struct Bin {
pub(crate) struct Bin {
pub name: Name,
pub path: PathBuf,
}

#[derive(Serialize, Clone, Debug)]
pub struct Name(pub String);
pub(crate) struct Name(pub String);

#[derive(Serialize, Debug)]
pub struct Config {
pub(crate) struct Config {
pub build: Build,
}

#[derive(Serialize, Debug)]
pub struct Build {
pub(crate) struct Build {
pub rustflags: Vec<&'static str>,
}

#[derive(Serialize, Debug)]
pub struct Workspace {
pub(crate) struct Workspace {
#[serde(skip_serializing_if = "Map::is_empty")]
pub dependencies: Map<String, Dependency>,
}
Expand Down
8 changes: 4 additions & 4 deletions src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::cmp;
use std::path::Path;

#[derive(Copy, Clone)]
pub struct Context<'a> {
pub(crate) struct Context<'a> {
pub krate: &'a str,
pub source_dir: &'a Directory,
pub workspace: &'a Directory,
Expand Down Expand Up @@ -73,7 +73,7 @@ normalizations! {
///
/// There is one "preferred" variation which is what we print when the stderr
/// file is absent or not a match.
pub fn diagnostics(output: &str, context: Context) -> Variations {
pub(crate) fn diagnostics(output: &str, context: Context) -> Variations {
let output = output.replace("\r\n", "\n");

let mut result = Variations::default();
Expand All @@ -84,7 +84,7 @@ pub fn diagnostics(output: &str, context: Context) -> Variations {
result
}

pub struct Variations {
pub(crate) struct Variations {
variations: [String; Normalization::ALL.len()],
}

Expand All @@ -107,7 +107,7 @@ impl Variations {
}
}

pub fn trim<S: AsRef<[u8]>>(output: S) -> String {
pub(crate) fn trim<S: AsRef<[u8]>>(output: S) -> String {
let bytes = output.as_ref();
let mut normalized = String::from_utf8_lossy(bytes).into_owned();

Expand Down

0 comments on commit 8562fca

Please sign in to comment.