-
-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This moves the logic previously found in BookmarkWriter's `with_underlying_table` into a common trait to be reused by other writers.
- Loading branch information
1 parent
e4c798f
commit d8082eb
Showing
5 changed files
with
28 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod bookmarks; | ||
pub mod parse; | ||
pub mod write; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use toml_edit::{array, ArrayOfTables, Table}; | ||
|
||
pub trait TableExt { | ||
/// Gets an existing array of tables, or creates a new one if it does not exist or type is different. | ||
fn get_or_create_array_of_tables(&mut self, key: &str) -> &mut ArrayOfTables; | ||
} | ||
|
||
impl TableExt for Table { | ||
fn get_or_create_array_of_tables(&mut self, key: &str) -> &mut ArrayOfTables { | ||
if self.contains_array_of_tables(key) { | ||
return self[key] | ||
.as_array_of_tables_mut() | ||
.expect("type was just verified"); | ||
} | ||
|
||
tracing::warn!("missing or invalid '{key}' array, recreating.."); | ||
self.insert(key, array()); | ||
self[key] | ||
.as_array_of_tables_mut() | ||
.expect("type was just created") | ||
} | ||
} |