diff --git a/crates/toml_edit/src/inline_table.rs b/crates/toml_edit/src/inline_table.rs index f1b28b09..82b54906 100644 --- a/crates/toml_edit/src/inline_table.rs +++ b/crates/toml_edit/src/inline_table.rs @@ -185,6 +185,11 @@ impl InlineTable { &self.decor } + /// Returns an accessor to a key's formatting + fn key(&mut self, key: &str) -> Option<&'_ Key> { + self.items.get(key).map(|kv| &kv.key) + } + /// Returns an accessor to a key's formatting pub fn key_mut(&mut self, key: &str) -> Option> { self.items.get_mut(key).map(|kv| kv.key.as_mut()) @@ -573,6 +578,9 @@ impl TableLike for InlineTable { self.is_dotted() } + fn key(&mut self, key: &str) -> Option<&'_ Key> { + self.key(key) + } fn key_mut(&mut self, key: &str) -> Option> { self.key_mut(key) } diff --git a/crates/toml_edit/src/table.rs b/crates/toml_edit/src/table.rs index e2792f51..199d17ae 100644 --- a/crates/toml_edit/src/table.rs +++ b/crates/toml_edit/src/table.rs @@ -218,6 +218,11 @@ impl Table { &self.decor } + /// Returns an accessor to a key's formatting + fn key(&mut self, key: &str) -> Option<&'_ Key> { + self.items.get(key).map(|kv| &kv.key) + } + /// Returns an accessor to a key's formatting pub fn key_mut(&mut self, key: &str) -> Option> { self.items.get_mut(key).map(|kv| kv.key.as_mut()) @@ -571,6 +576,8 @@ pub trait TableLike: crate::private::Sealed { /// Check if this is a wrapper for dotted keys, rather than a standard table fn is_dotted(&self) -> bool; + /// Returns an accessor to a key's formatting + fn key(&mut self, key: &str) -> Option<&'_ Key>; /// Returns an accessor to a key's formatting fn key_mut(&mut self, key: &str) -> Option>; /// Returns the decor associated with a given key of the table. @@ -635,6 +642,9 @@ impl TableLike for Table { self.set_dotted(yes) } + fn key(&mut self, key: &str) -> Option<&'_ Key> { + self.key(key) + } fn key_mut(&mut self, key: &str) -> Option> { self.key_mut(key) }