Skip to content

Commit 5b5966d

Browse files
refactor: replace unwrap with idiomatic get_or_insert_with in add_submodule
This change refactors `SubmoduleEntries::add_submodule` to use `get_or_insert_with(HashMap::new)` instead of a manual `is_some()` check followed by `unwrap()`. This improves code readability and follows Rust idioms for handling `Option` types. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
1 parent a50023b commit 5b5966d

1 file changed

Lines changed: 4 additions & 16 deletions

File tree

src/config.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -739,22 +739,10 @@ impl SubmoduleEntries {
739739
}
740740

741741
/// Add a submodule entry
742-
#[must_use] pub fn add_submodule(self, name: SubmoduleName, entry: SubmoduleEntry) -> Self {
743-
if self.submodules().is_some() {
744-
let mut submodules = self.submodules.unwrap();
745-
submodules.insert(name, entry);
746-
Self {
747-
submodules: Some(submodules),
748-
sparse_checkouts: self.sparse_checkouts,
749-
}
750-
} else {
751-
let mut submodules = HashMap::new();
752-
submodules.insert(name, entry);
753-
Self {
754-
submodules: Some(submodules),
755-
sparse_checkouts: self.sparse_checkouts,
756-
}
757-
}
742+
#[must_use] pub fn add_submodule(mut self, name: SubmoduleName, entry: SubmoduleEntry) -> Self {
743+
let submodules = self.submodules.get_or_insert_with(HashMap::new);
744+
submodules.insert(name, entry);
745+
self
758746
}
759747

760748
/// Remove a submodule entry

0 commit comments

Comments
 (0)