settings: Use a derive macro for refine (#38451)
When we refactored settings to not pass JSON blobs around, we ended up needing to write *a lot* of code that just merged things (like json merge used to do). Use a derive macro to prevent typos in this logic. Release Notes: - N/A
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use gpui::App;
|
||||
pub use settings::ImageFileSizeUnit;
|
||||
use settings::Settings;
|
||||
use util::MergeFrom;
|
||||
|
||||
/// The settings for the image viewer.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@@ -13,18 +12,9 @@ pub struct ImageViewerSettings {
|
||||
}
|
||||
|
||||
impl Settings for ImageViewerSettings {
|
||||
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
Self {
|
||||
unit: content.image_viewer.clone().unwrap().unit.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
|
||||
self.unit.merge_from(
|
||||
&content
|
||||
.image_viewer
|
||||
.as_ref()
|
||||
.and_then(|image_viewer| image_viewer.unit),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user