Skip to content

Commit c8f8e63

Browse files
committed
fix: borrow in /todo add; make ConfigManager::start_watch use interior mutability
1 parent 1e9d9f3 commit c8f8e63

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

Cargo.lock

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/layered_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl ConfigManager {
302302
Ok(())
303303
}
304304

305-
fn start_watch(&mut self) -> Result<()> {
305+
fn start_watch(&self) -> Result<()> {
306306
let system = self.system_path.clone();
307307
let user = self.user_path.clone();
308308
let workspace = self.workspace_path.clone();

src/slash.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,15 @@ impl SlashRegistry {
137137
.iter().filter_map(|x| x.as_str().map(|s| self.workspace_root.join(s))).collect();
138138
let tags: Vec<String> = v.get("tags").and_then(|x| x.as_array()).unwrap_or(&vec![])
139139
.iter().filter_map(|x| x.as_str().map(|s| s.to_string())).collect();
140-
let it = store.add(title.to_string(), desc, files, tags);
141-
store.save(&path)?;
142-
Ok(format!("todo added: {} ({})", it.title, it.id))
140+
// Capture data we need without holding a borrow across save()
141+
{
142+
let it = store.add(title.to_string(), desc, files, tags);
143+
let title_owned = it.title.clone();
144+
let id_owned = it.id.clone();
145+
drop(it);
146+
store.save(&path)?;
147+
return Ok(format!("todo added: {} ({})", title_owned, id_owned));
148+
}
143149
}
144150
"list" => {
145151
let mut s = String::new();

0 commit comments

Comments
 (0)