Skip to content

Commit b2a0998

Browse files
committed
feat: Simplify save_with method
1 parent 1369d86 commit b2a0998

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

espflash/src/cli/config.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,21 @@ impl Config {
159159
let mut copy = self.clone();
160160
modify_fn(&mut copy);
161161

162-
// Save port configuration
163-
let port_serialized = toml::to_string(&copy.port_config)
162+
let serialized = toml::to_string(&copy.port_config)
164163
.into_diagnostic()
165-
.wrap_err("Failed to serialize port config")?;
166-
if let Some(parent) = copy.port_config.save_path.parent() {
167-
create_dir_all(parent)
168-
.into_diagnostic()
169-
.wrap_err("Failed to create port config directory")?;
170-
}
171-
write(&copy.port_config.save_path, port_serialized)
164+
.wrap_err("Failed to serialize config")?;
165+
166+
create_dir_all(self.port_config.save_path.parent().unwrap())
167+
.into_diagnostic()
168+
.wrap_err("Failed to create config directory")?;
169+
write(&self.port_config.save_path, serialized)
172170
.into_diagnostic()
173171
.wrap_err_with(|| {
174172
format!(
175-
"Failed to write port config to {}",
176-
copy.port_config.save_path.display()
173+
"Failed to write config to {}",
174+
self.port_config.save_path.display()
177175
)
178-
})?;
179-
180-
Ok(())
176+
})
181177
}
182178

183179
fn project_config_path() -> Result<PathBuf, Error> {

0 commit comments

Comments
 (0)