Skip to content

Commit 5353f81

Browse files
committed
Use serde for deserializing strip option
1 parent e768b17 commit 5353f81

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/cargo/core/profiles.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,7 @@ fn merge_profile(profile: &mut Profile, toml: &TomlProfile) {
566566
profile.incremental = incremental;
567567
}
568568
if let Some(strip) = toml.strip {
569-
profile.strip = match strip.as_str() {
570-
"debuginfo" => Strip::DebugInfo,
571-
"none" => Strip::None,
572-
"symbols" => Strip::Symbols,
573-
_ => panic!("Unexpected strip option `{}`", strip),
574-
};
569+
profile.strip = strip;
575570
}
576571
}
577572

@@ -790,7 +785,9 @@ impl fmt::Display for PanicStrategy {
790785
}
791786

792787
/// The setting for choosing which symbols to strip
793-
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize)]
788+
#[derive(
789+
Clone, Copy, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
790+
)]
794791
#[serde(rename_all = "lowercase")]
795792
pub enum Strip {
796793
/// Only strip debugging symbols

src/cargo/util/toml/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use url::Url;
1515

1616
use crate::core::dependency::DepKind;
1717
use crate::core::manifest::{ManifestMetadata, TargetSourcePath, Warnings};
18+
use crate::core::profiles::Strip;
1819
use crate::core::resolver::ResolveBehavior;
1920
use crate::core::{Dependency, InternedString, Manifest, PackageId, Summary, Target};
2021
use crate::core::{Edition, EitherManifest, Feature, Features, VirtualManifest, Workspace};
@@ -407,7 +408,7 @@ pub struct TomlProfile {
407408
pub build_override: Option<Box<TomlProfile>>,
408409
pub dir_name: Option<InternedString>,
409410
pub inherits: Option<InternedString>,
410-
pub strip: Option<InternedString>,
411+
pub strip: Option<Strip>,
411412
}
412413

413414
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
@@ -524,15 +525,8 @@ impl TomlProfile {
524525
}
525526
}
526527

527-
if let Some(strip) = &self.strip {
528+
if self.strip.is_some() {
528529
features.require(Feature::strip())?;
529-
if strip != "debuginfo" && strip != "none" && strip != "symbols" {
530-
bail!(
531-
"`strip` setting of `{}` is not a valid setting,\
532-
must be `debuginfo`, `none` or `symbols`",
533-
strip
534-
);
535-
}
536530
}
537531
Ok(())
538532
}

0 commit comments

Comments
 (0)