From a96de8a4868b45d1afca5be34ded1aa078b4ab9e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 31 Oct 2023 16:28:39 -0500 Subject: [PATCH] feat(toml): Publically expose all schema types --- src/cargo/util/toml/mod.rs | 307 ++++++++++++++++++------------------- 1 file changed, 153 insertions(+), 154 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index f6d6c5ea5e19..6f80cd3cab51 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -192,29 +192,29 @@ fn warn_on_deprecated(new_path: &str, name: &str, kind: &str, warnings: &mut Vec #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] pub struct TomlManifest { - cargo_features: Option>, - package: Option>, - project: Option>, - profile: Option, - lib: Option, - bin: Option>, - example: Option>, - test: Option>, - bench: Option>, - dependencies: Option>, - dev_dependencies: Option>, + pub cargo_features: Option>, + pub package: Option>, + pub project: Option>, + pub profile: Option, + pub lib: Option, + pub bin: Option>, + pub example: Option>, + pub test: Option>, + pub bench: Option>, + pub dependencies: Option>, + pub dev_dependencies: Option>, #[serde(rename = "dev_dependencies")] - dev_dependencies2: Option>, - build_dependencies: Option>, + pub dev_dependencies2: Option>, + pub build_dependencies: Option>, #[serde(rename = "build_dependencies")] - build_dependencies2: Option>, - features: Option>>, - target: Option>, - replace: Option>, - patch: Option>>, - workspace: Option, - badges: Option, - lints: Option, + pub build_dependencies2: Option>, + pub features: Option>>, + pub target: Option>, + pub replace: Option>, + pub patch: Option>>, + pub workspace: Option, + pub badges: Option, + pub lints: Option, } impl TomlManifest { @@ -1532,16 +1532,16 @@ fn unique_build_targets( #[derive(Debug, Deserialize, Serialize, Clone)] #[serde(rename_all = "kebab-case")] pub struct TomlWorkspace { - members: Option>, - exclude: Option>, - default_members: Option>, - resolver: Option, - metadata: Option, + pub members: Option>, + pub exclude: Option>, + pub default_members: Option>, + pub resolver: Option, + pub metadata: Option, // Properties that can be inherited by members. - package: Option, - dependencies: Option>, - lints: Option, + pub package: Option, + pub dependencies: Option>, + pub lints: Option, } /// A group of fields that are inheritable by members of the workspace @@ -1551,31 +1551,31 @@ pub struct InheritableFields { // We use skip here since it will never be present when deserializing // and we don't want it present when serializing #[serde(skip)] - dependencies: Option>, + pub dependencies: Option>, #[serde(skip)] - lints: Option, - - version: Option, - authors: Option>, - description: Option, - homepage: Option, - documentation: Option, - readme: Option, - keywords: Option>, - categories: Option>, - license: Option, - license_file: Option, - repository: Option, - publish: Option, - edition: Option, - badges: Option>>, - exclude: Option>, - include: Option>, - rust_version: Option, + pub lints: Option, + + pub version: Option, + pub authors: Option>, + pub description: Option, + pub homepage: Option, + pub documentation: Option, + pub readme: Option, + pub keywords: Option>, + pub categories: Option>, + pub license: Option, + pub license_file: Option, + pub repository: Option, + pub publish: Option, + pub edition: Option, + pub badges: Option>>, + pub exclude: Option>, + pub include: Option>, + pub rust_version: Option, // We use skip here since it will never be present when deserializing // and we don't want it present when serializing #[serde(skip)] - ws_root: PathBuf, + pub ws_root: PathBuf, } /// Defines simple getter methods for inheritable fields. @@ -1673,44 +1673,44 @@ impl InheritableFields { #[derive(Deserialize, Serialize, Clone, Debug)] #[serde(rename_all = "kebab-case")] pub struct TomlPackage { - edition: Option, - rust_version: Option, - name: String, - version: Option, - authors: Option, - build: Option, - metabuild: Option, - default_target: Option, - forced_target: Option, - links: Option, - exclude: Option, - include: Option, - publish: Option, - workspace: Option, - im_a_teapot: Option, - autobins: Option, - autoexamples: Option, - autotests: Option, - autobenches: Option, - default_run: Option, + pub edition: Option, + pub rust_version: Option, + pub name: String, + pub version: Option, + pub authors: Option, + pub build: Option, + pub metabuild: Option, + pub default_target: Option, + pub forced_target: Option, + pub links: Option, + pub exclude: Option, + pub include: Option, + pub publish: Option, + pub workspace: Option, + pub im_a_teapot: Option, + pub autobins: Option, + pub autoexamples: Option, + pub autotests: Option, + pub autobenches: Option, + pub default_run: Option, // Package metadata. - description: Option, - homepage: Option, - documentation: Option, - readme: Option, - keywords: Option, - categories: Option, - license: Option, - license_file: Option, - repository: Option, - resolver: Option, - - metadata: Option, + pub description: Option, + pub homepage: Option, + pub documentation: Option, + pub readme: Option, + pub keywords: Option, + pub categories: Option, + pub license: Option, + pub license_file: Option, + pub repository: Option, + pub resolver: Option, + + pub metadata: Option, /// Provide a helpful error message for a common user error. #[serde(rename = "cargo-features", skip_serializing)] - _invalid_cargo_features: Option, + pub _invalid_cargo_features: Option, } impl TomlPackage { @@ -1790,7 +1790,7 @@ impl MaybeWorkspace { } //. This already has a `Deserialize` impl from version_trim_whitespace -type MaybeWorkspaceSemverVersion = MaybeWorkspace; +pub type MaybeWorkspaceSemverVersion = MaybeWorkspace; impl<'de> de::Deserialize<'de> for MaybeWorkspaceSemverVersion { fn deserialize(d: D) -> Result where @@ -1809,7 +1809,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceSemverVersion { } } -type MaybeWorkspaceString = MaybeWorkspace; +pub type MaybeWorkspaceString = MaybeWorkspace; impl<'de> de::Deserialize<'de> for MaybeWorkspaceString { fn deserialize(d: D) -> Result where @@ -1844,7 +1844,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceString { } } -type MaybeWorkspaceRustVersion = MaybeWorkspace; +pub type MaybeWorkspaceRustVersion = MaybeWorkspace; impl<'de> de::Deserialize<'de> for MaybeWorkspaceRustVersion { fn deserialize(d: D) -> Result where @@ -1880,7 +1880,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceRustVersion { } } -type MaybeWorkspaceVecString = MaybeWorkspace, TomlWorkspaceField>; +pub type MaybeWorkspaceVecString = MaybeWorkspace, TomlWorkspaceField>; impl<'de> de::Deserialize<'de> for MaybeWorkspaceVecString { fn deserialize(d: D) -> Result where @@ -1915,7 +1915,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceVecString { } } -type MaybeWorkspaceStringOrBool = MaybeWorkspace; +pub type MaybeWorkspaceStringOrBool = MaybeWorkspace; impl<'de> de::Deserialize<'de> for MaybeWorkspaceStringOrBool { fn deserialize(d: D) -> Result where @@ -1959,7 +1959,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceStringOrBool { } } -type MaybeWorkspaceVecStringOrBool = MaybeWorkspace; +pub type MaybeWorkspaceVecStringOrBool = MaybeWorkspace; impl<'de> de::Deserialize<'de> for MaybeWorkspaceVecStringOrBool { fn deserialize(d: D) -> Result where @@ -2003,7 +2003,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceVecStringOrBool { } } -type MaybeWorkspaceBtreeMap = +pub type MaybeWorkspaceBtreeMap = MaybeWorkspace>, TomlWorkspaceField>; impl<'de> de::Deserialize<'de> for MaybeWorkspaceBtreeMap { @@ -2031,7 +2031,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceBtreeMap { #[serde(rename_all = "kebab-case")] pub struct TomlWorkspaceField { #[serde(deserialize_with = "bool_no_false")] - workspace: bool, + pub workspace: bool, } impl WorkspaceInherit for TomlWorkspaceField { @@ -2053,7 +2053,7 @@ fn bool_no_false<'de, D: de::Deserializer<'de>>(deserializer: D) -> Result; +pub type MaybeWorkspaceDependency = MaybeWorkspace; impl MaybeWorkspaceDependency { fn unused_keys(&self) -> Vec { @@ -2089,18 +2089,18 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceDependency { #[derive(Deserialize, Serialize, Clone, Debug)] #[serde(rename_all = "kebab-case")] pub struct TomlWorkspaceDependency { - workspace: bool, - features: Option>, - default_features: Option, + pub workspace: bool, + pub features: Option>, + pub default_features: Option, #[serde(rename = "default_features")] - default_features2: Option, - optional: Option, - public: Option, + pub default_features2: Option, + pub optional: Option, + pub public: Option, /// This is here to provide a way to see the "unused manifest keys" when deserializing #[serde(skip_serializing)] #[serde(flatten)] - unused_keys: BTreeMap, + pub unused_keys: BTreeMap, } impl TomlWorkspaceDependency { @@ -2292,41 +2292,41 @@ impl<'de, P: Deserialize<'de> + Clone> de::Deserialize<'de> for TomlDependency

{ - version: Option, - registry: Option, + pub version: Option, + pub registry: Option, /// The URL of the `registry` field. /// This is an internal implementation detail. When Cargo creates a /// package, it replaces `registry` with `registry-index` so that the /// manifest contains the correct URL. All users won't have the same /// registry names configured, so Cargo can't rely on just the name for /// crates published by other users. - registry_index: Option, + pub registry_index: Option, // `path` is relative to the file it appears in. If that's a `Cargo.toml`, it'll be relative to // that TOML file, and if it's a `.cargo/config` file, it'll be relative to that file. - path: Option

, - git: Option, - branch: Option, - tag: Option, - rev: Option, - features: Option>, - optional: Option, - default_features: Option, + pub path: Option

, + pub git: Option, + pub branch: Option, + pub tag: Option, + pub rev: Option, + pub features: Option>, + pub optional: Option, + pub default_features: Option, #[serde(rename = "default_features")] - default_features2: Option, - package: Option, - public: Option, + pub default_features2: Option, + pub package: Option, + pub public: Option, /// One or more of `bin`, `cdylib`, `staticlib`, `bin:`. - artifact: Option, + pub artifact: Option, /// If set, the artifact should also be a dependency - lib: Option, + pub lib: Option, /// A platform name, like `x86_64-apple-darwin` - target: Option, + pub target: Option, /// This is here to provide a way to see the "unused manifest keys" when deserializing #[serde(skip_serializing)] #[serde(flatten)] - unused_keys: BTreeMap, + pub unused_keys: BTreeMap, } impl DetailedTomlDependency { @@ -2638,7 +2638,7 @@ impl Default for DetailedTomlDependency

{ } #[derive(Deserialize, Serialize, Clone, Debug, Default)] -pub struct TomlProfiles(BTreeMap); +pub struct TomlProfiles(pub BTreeMap); impl TomlProfiles { pub fn get_all(&self) -> &BTreeMap { @@ -3291,39 +3291,39 @@ impl fmt::Display for TomlTrimPathsValue { } } -type TomlLibTarget = TomlTarget; -type TomlBinTarget = TomlTarget; -type TomlExampleTarget = TomlTarget; -type TomlTestTarget = TomlTarget; -type TomlBenchTarget = TomlTarget; +pub type TomlLibTarget = TomlTarget; +pub type TomlBinTarget = TomlTarget; +pub type TomlExampleTarget = TomlTarget; +pub type TomlTestTarget = TomlTarget; +pub type TomlBenchTarget = TomlTarget; #[derive(Default, Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "kebab-case")] -struct TomlTarget { - name: Option, +pub struct TomlTarget { + pub name: Option, // The intention was to only accept `crate-type` here but historical // versions of Cargo also accepted `crate_type`, so look for both. - crate_type: Option>, + pub crate_type: Option>, #[serde(rename = "crate_type")] - crate_type2: Option>, + pub crate_type2: Option>, - path: Option, + pub path: Option, // Note that `filename` is used for the cargo-feature `different_binary_name` - filename: Option, - test: Option, - doctest: Option, - bench: Option, - doc: Option, - plugin: Option, - doc_scrape_examples: Option, + pub filename: Option, + pub test: Option, + pub doctest: Option, + pub bench: Option, + pub doc: Option, + pub plugin: Option, + pub doc_scrape_examples: Option, #[serde(rename = "proc-macro")] - proc_macro_raw: Option, + pub proc_macro_raw: Option, #[serde(rename = "proc_macro")] - proc_macro_raw2: Option, - harness: Option, - required_features: Option>, - edition: Option, + pub proc_macro_raw2: Option, + pub harness: Option, + pub required_features: Option>, + pub edition: Option, } impl TomlTarget { @@ -3381,14 +3381,14 @@ impl TomlTarget { /// Corresponds to a `target` entry, but `TomlTarget` is already used. #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "kebab-case")] -struct TomlPlatform { - dependencies: Option>, - build_dependencies: Option>, +pub struct TomlPlatform { + pub dependencies: Option>, + pub build_dependencies: Option>, #[serde(rename = "build_dependencies")] - build_dependencies2: Option>, - dev_dependencies: Option>, + pub build_dependencies2: Option>, + pub dev_dependencies: Option>, #[serde(rename = "dev_dependencies")] - dev_dependencies2: Option>, + pub dev_dependencies2: Option>, } #[derive(Deserialize, Serialize, Debug, Clone)] @@ -3397,9 +3397,9 @@ struct TomlPlatform { pub struct MaybeWorkspaceLints { #[serde(skip_serializing_if = "is_false")] #[serde(deserialize_with = "bool_no_false", default)] - workspace: bool, + pub workspace: bool, #[serde(flatten)] - lints: TomlLints, + pub lints: TomlLints, } fn is_false(b: &bool) -> bool { @@ -3468,9 +3468,9 @@ impl TomlLint { #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "kebab-case")] pub struct TomlLintConfig { - level: TomlLintLevel, + pub level: TomlLintLevel, #[serde(default)] - priority: i8, + pub priority: i8, } #[derive(Serialize, Deserialize, Debug, Copy, Clone)] @@ -3494,8 +3494,7 @@ impl TomlLintLevel { } #[derive(Copy, Clone, Debug)] -#[non_exhaustive] -struct InvalidCargoFeatures {} +pub struct InvalidCargoFeatures {} impl<'de> de::Deserialize<'de> for InvalidCargoFeatures { fn deserialize(_d: D) -> Result @@ -3529,7 +3528,7 @@ impl ResolveToPath for ConfigRelativePath { /// A StringOrVec can be parsed from either a TOML string or array, /// but is always stored as a vector. #[derive(Clone, Debug, Serialize, Eq, PartialEq, PartialOrd, Ord)] -pub struct StringOrVec(Vec); +pub struct StringOrVec(pub Vec); impl StringOrVec { pub fn iter<'a>(&'a self) -> std::slice::Iter<'a, String> { @@ -3590,7 +3589,7 @@ impl<'de> de::Deserialize<'de> for VecStringOrBool { } #[derive(Clone)] -struct PathValue(PathBuf); +pub struct PathValue(pub PathBuf); impl fmt::Debug for PathValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {