Created
March 11, 2026 15:03
-
-
Save huitseeker/ae37b40fae6047e264ae3742e9172b25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git i/crates/project/src/profile.rs w/crates/project/src/profile.rs | |
| index 85df31b8d..b25654512 100644 | |
| --- i/crates/project/src/profile.rs | |
| +++ w/crates/project/src/profile.rs | |
| @@ -22,6 +22,70 @@ pub struct Profile { | |
| metadata: Metadata, | |
| } | |
| +trait ProfileOverrides { | |
| + fn debug_override(&self) -> Option<bool>; | |
| + fn trim_paths_override(&self) -> Option<bool>; | |
| + fn metadata_override(&self) -> &Metadata; | |
| +} | |
| + | |
| +impl ProfileOverrides for Profile { | |
| + fn debug_override(&self) -> Option<bool> { | |
| + Some(self.debug) | |
| + } | |
| + | |
| + fn trim_paths_override(&self) -> Option<bool> { | |
| + Some(self.trim_paths) | |
| + } | |
| + | |
| + fn metadata_override(&self) -> &Metadata { | |
| + &self.metadata | |
| + } | |
| +} | |
| + | |
| +#[cfg(feature = "serde")] | |
| +impl ProfileOverrides for ast::Profile { | |
| + fn debug_override(&self) -> Option<bool> { | |
| + self.debug | |
| + } | |
| + | |
| + fn trim_paths_override(&self) -> Option<bool> { | |
| + self.trim_paths | |
| + } | |
| + | |
| + fn metadata_override(&self) -> &Metadata { | |
| + &self.metadata | |
| + } | |
| +} | |
| + | |
| +fn apply_overrides(target: &mut Profile, source: &impl ProfileOverrides) { | |
| + if let Some(debug) = source.debug_override() { | |
| + target.debug = debug; | |
| + } | |
| + | |
| + if let Some(trim_paths) = source.trim_paths_override() { | |
| + target.trim_paths = trim_paths; | |
| + } | |
| + | |
| + for (k, v2) in source.metadata_override().iter() { | |
| + if let Some(v) = target.metadata.get_mut(k) { | |
| + match &mut **v { | |
| + Value::Table(table) => { | |
| + if let Value::Table(table2) = v2.inner() { | |
| + table.extend(table2.iter().map(|(k, v)| (k.clone(), v.clone()))); | |
| + } else { | |
| + *v = v2.clone(); | |
| + } | |
| + }, | |
| + _ => { | |
| + *v = v2.clone(); | |
| + }, | |
| + } | |
| + } else { | |
| + target.metadata.insert(k.clone(), v2.clone()); | |
| + } | |
| + } | |
| +} | |
| + | |
| impl Default for Profile { | |
| /// Constructs the default 'dev' profile in a debug-friendly configuration | |
| fn default() -> Self { | |
| @@ -71,9 +135,9 @@ impl Profile { | |
| let ast::Profile { | |
| inherits, | |
| name, | |
| - debug, | |
| - trim_paths, | |
| - metadata, | |
| + debug: _, | |
| + trim_paths: _, | |
| + metadata: _, | |
| } = ast; | |
| let mut profile = match inherits.as_ref() { | |
| @@ -92,17 +156,7 @@ impl Profile { | |
| None => Profile::new(name.clone()), | |
| }; | |
| - if let Some(debug) = *debug { | |
| - profile.enable_debug_info(debug); | |
| - } | |
| - | |
| - if let Some(trim_paths) = *trim_paths { | |
| - profile.enable_trim_paths(trim_paths); | |
| - } | |
| - | |
| - if !metadata.is_empty() { | |
| - profile.extend(metadata.iter().map(|(k, v)| (k.clone(), v.clone()))); | |
| - } | |
| + apply_overrides(&mut profile, ast); | |
| Ok(profile) | |
| } | |
| @@ -112,26 +166,7 @@ impl Profile { | |
| /// This has the effect of overriding any options in `self` which have different values in | |
| /// `other`. | |
| pub fn merge(&mut self, other: &Self) { | |
| - let Self { name: _, debug, trim_paths, metadata } = self; | |
| - | |
| - *debug = other.debug; | |
| - *trim_paths = other.trim_paths; | |
| - for (k, v) in metadata.iter_mut() { | |
| - if let Some(v2) = other.metadata.get(k) { | |
| - match &mut **v { | |
| - Value::Table(table) => { | |
| - if let Value::Table(table2) = v2.inner() { | |
| - table.extend(table2.iter().map(|(k, v)| (k.clone(), v.clone()))); | |
| - } else { | |
| - *v = v2.clone(); | |
| - } | |
| - }, | |
| - _ => { | |
| - *v = v2.clone(); | |
| - }, | |
| - } | |
| - } | |
| - } | |
| + apply_overrides(self, other); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment