Struct toml_edit::InlineVacantEntry
source · pub struct InlineVacantEntry<'a> { /* private fields */ }
Expand description
A view into a single empty location in a IndexMap
.
Implementations§
source§impl<'a> InlineVacantEntry<'a>
impl<'a> InlineVacantEntry<'a>
sourcepub fn key(&self) -> &str
pub fn key(&self) -> &str
Gets a reference to the entry key
Examples
use toml_edit::Table;
let mut map = Table::new();
assert_eq!("foo", map.entry("foo").key());
sourcepub fn insert(self, value: Value) -> &'a mut Value
pub fn insert(self, value: Value) -> &'a mut Value
Sets the value of the entry with the VacantEntry’s key, and returns a mutable reference to it
Examples found in repository?
src/inline_table.rs (line 528)
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
pub fn or_insert(self, default: Value) -> &'a mut Value {
match self {
InlineEntry::Occupied(entry) => entry.into_mut(),
InlineEntry::Vacant(entry) => entry.insert(default),
}
}
/// Ensures a value is in the entry by inserting the result of the default function if empty,
/// and returns a mutable reference to the value in the entry.
pub fn or_insert_with<F: FnOnce() -> Value>(self, default: F) -> &'a mut Value {
match self {
InlineEntry::Occupied(entry) => entry.into_mut(),
InlineEntry::Vacant(entry) => entry.insert(default()),
}
}