pub struct Table { /* private fields */ }
Expand description
Type representing a TOML non-inline table
Implementations
sourceimpl Table
impl Table
Constructors
See also FromIterator
sourcepub fn into_inline_table(self) -> InlineTable
pub fn into_inline_table(self) -> InlineTable
Convert to an inline table
sourceimpl Table
impl Table
Formatting
sourcepub fn get_values(&self) -> Vec<(Vec<&Key>, &Value)>
pub fn get_values(&self) -> Vec<(Vec<&Key>, &Value)>
Get key/values for values that are visually children of this table
For example, this will return dotted keys
sourcepub fn sort_values(&mut self)
pub fn sort_values(&mut self)
Sorts Key/Value Pairs of the table.
Doesn’t affect subtables or subarrays.
sourcepub fn sort_values_by<F>(&mut self, compare: F) where
F: FnMut(&Key, &Item, &Key, &Item) -> Ordering,
pub fn sort_values_by<F>(&mut self, compare: F) where
F: FnMut(&Key, &Item, &Key, &Item) -> Ordering,
Sort Key/Value Pairs of the table using the using the comparison function compare
.
The comparison function receives two key and value pairs to compare (you can sort by keys or values or their combination as needed).
sourcepub fn set_implicit(&mut self, implicit: bool)
pub fn set_implicit(&mut self, implicit: bool)
If a table has no key/value pairs and implicit, it will not be displayed.
Examples
[target."x86_64/windows.json".dependencies]
In the document above, tables target
and target."x86_64/windows.json"
are implicit.
use toml_edit::Document;
let mut doc = "[a]\n[a.b]\n".parse::<Document>().expect("invalid toml");
doc["a"].as_table_mut().unwrap().set_implicit(true);
assert_eq!(doc.to_string(), "[a.b]\n");
sourcepub fn is_implicit(&self) -> bool
pub fn is_implicit(&self) -> bool
If a table has no key/value pairs and implicit, it will not be displayed.
sourcepub fn set_dotted(&mut self, yes: bool)
pub fn set_dotted(&mut self, yes: bool)
Change this table’s dotted status
sourcepub fn is_dotted(&self) -> bool
pub fn is_dotted(&self) -> bool
Check if this is a wrapper for dotted keys, rather than a standard table
sourcepub fn set_position(&mut self, doc_position: usize)
pub fn set_position(&mut self, doc_position: usize)
Sets the position of the Table
within the Document
.
sourcepub fn position(&self) -> Option<usize>
pub fn position(&self) -> Option<usize>
The position of the Table
within the Document
.
Returns None
if the Table
was created manually (i.e. not via parsing)
in which case its position is set automatically. This can be overridden with
Table::set_position
.
sourcepub fn key_decor_mut(&mut self, key: &str) -> Option<&mut Decor>
pub fn key_decor_mut(&mut self, key: &str) -> Option<&mut Decor>
Returns the decor associated with a given key of the table.
sourceimpl Table
impl Table
sourcepub fn iter_mut(&mut self) -> IterMut<'_>
pub fn iter_mut(&mut self) -> IterMut<'_>
Returns an mutable iterator over all key/value pairs, including empty.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the table, removing all key-value pairs. Keeps the allocated memory for reuse.
sourcepub fn entry<'a>(&'a mut self, key: &str) -> Entry<'a>
pub fn entry<'a>(&'a mut self, key: &str) -> Entry<'a>
Gets the given key’s corresponding entry in the Table for in-place manipulation.
sourcepub fn entry_format<'a>(&'a mut self, key: &Key) -> Entry<'a>
pub fn entry_format<'a>(&'a mut self, key: &Key) -> Entry<'a>
Gets the given key’s corresponding entry in the Table for in-place manipulation.
sourcepub fn get<'a>(&'a self, key: &str) -> Option<&'a Item>
pub fn get<'a>(&'a self, key: &str) -> Option<&'a Item>
Returns an optional reference to an item given the key.
sourcepub fn get_mut<'a>(&'a mut self, key: &str) -> Option<&'a mut Item>
pub fn get_mut<'a>(&'a mut self, key: &str) -> Option<&'a mut Item>
Returns an optional mutable reference to an item given the key.
sourcepub fn get_key_value<'a>(&'a self, key: &str) -> Option<(&'a Key, &'a Item)>
pub fn get_key_value<'a>(&'a self, key: &str) -> Option<(&'a Key, &'a Item)>
Return references to the key-value pair stored for key, if it is present, else None.
sourcepub fn get_key_value_mut<'a>(
&'a mut self,
key: &str
) -> Option<(KeyMut<'a>, &'a mut Item)>
pub fn get_key_value_mut<'a>(
&'a mut self,
key: &str
) -> Option<(KeyMut<'a>, &'a mut Item)>
Return mutable references to the key-value pair stored for key, if it is present, else None.
sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Returns true iff the table contains an item with the given key.
sourcepub fn contains_table(&self, key: &str) -> bool
pub fn contains_table(&self, key: &str) -> bool
Returns true iff the table contains a table with the given key.
sourcepub fn contains_value(&self, key: &str) -> bool
pub fn contains_value(&self, key: &str) -> bool
Returns true iff the table contains a value with the given key.
sourcepub fn contains_array_of_tables(&self, key: &str) -> bool
pub fn contains_array_of_tables(&self, key: &str) -> bool
Returns true iff the table contains an array of tables with the given key.
sourcepub fn insert(&mut self, key: &str, item: Item) -> Option<Item>
pub fn insert(&mut self, key: &str, item: Item) -> Option<Item>
Inserts a key-value pair into the map.
Trait Implementations
sourceimpl<'de, 'a> Deserializer<'de> for Table
impl<'de, 'a> Deserializer<'de> for Table
type Error = Error
type Error = Error
The error type that can be returned if some error occurs during deserialization. Read more
sourcefn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Require the Deserializer
to figure out how to drive the visitor based
on what data type is in the input. Read more
sourcefn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error> where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an optional value. Read more
sourcefn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Error> where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a newtype struct with a
particular name. Read more
sourcefn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Error> where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a struct with a particular
name and fields. Read more
sourcefn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Error> where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an enum value with a
particular name and possible variants. Read more
sourcefn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a bool
value.
sourcefn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a u8
value.
sourcefn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a u16
value.
sourcefn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a u32
value.
sourcefn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a u64
value.
sourcefn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an i8
value.
sourcefn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an i16
value.
sourcefn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an i32
value.
sourcefn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an i64
value.
sourcefn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a f32
value.
sourcefn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a f64
value.
sourcefn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a char
value.
sourcefn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
sourcefn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
sourcefn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a sequence of values.
sourcefn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
sourcefn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
sourcefn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a map of key-value pairs.
sourcefn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a unit value.
sourcefn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read more
sourcefn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a unit struct with a
particular name. Read more
sourcefn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a tuple struct with a
particular name and number of fields. Read more
sourcefn deserialize_tuple<V>(
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_tuple<V>(
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting a sequence of values and
knows how many values there are without looking at the serialized data. Read more
sourcefn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting the name of a struct
field or the discriminant of an enum variant. Read more
sourcefn deserialize_i128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_i128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an i128
value. Read more
sourcefn deserialize_u128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
V: Visitor<'de>,
fn deserialize_u128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error> where
V: Visitor<'de>,
Hint that the Deserialize
type is expecting an u128
value. Read more
sourcefn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Determine whether Deserialize
implementations should expect to
deserialize their human-readable form. Read more
sourceimpl<K: Into<Key>, V: Into<Value>> Extend<(K, V)> for Table
impl<K: Into<Key>, V: Into<Value>> Extend<(K, V)> for Table
sourcefn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl Extend<Table> for ArrayOfTables
impl Extend<Table> for ArrayOfTables
sourcefn extend<T: IntoIterator<Item = Table>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Table>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<K: Into<Key>, V: Into<Value>> FromIterator<(K, V)> for Table
impl<K: Into<Key>, V: Into<Value>> FromIterator<(K, V)> for Table
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
Creates a value from an iterator. Read more
sourceimpl FromIterator<Table> for ArrayOfTables
impl FromIterator<Table> for ArrayOfTables
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = Table>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = Table>,
Creates a value from an iterator. Read more
sourceimpl<'de> IntoDeserializer<'de, Error> for Table
impl<'de> IntoDeserializer<'de, Error> for Table
type Deserializer = Table
type Deserializer = Table
The type of the deserializer being converted into.
sourcefn into_deserializer(self) -> Self
fn into_deserializer(self) -> Self
Convert this value into a deserializer.
sourceimpl IntoIterator for Table
impl IntoIterator for Table
sourceimpl<'s> IntoIterator for &'s Table
impl<'s> IntoIterator for &'s Table
sourceimpl TableLike for Table
impl TableLike for Table
sourcefn iter_mut(&mut self) -> IterMut<'_>
fn iter_mut(&mut self) -> IterMut<'_>
Returns an mutable iterator over all key/value pairs, including empty.
sourcefn clear(&mut self)
fn clear(&mut self)
Clears the table, removing all key-value pairs. Keeps the allocated memory for reuse.
sourcefn entry<'a>(&'a mut self, key: &str) -> Entry<'a>
fn entry<'a>(&'a mut self, key: &str) -> Entry<'a>
Gets the given key’s corresponding entry in the Table for in-place manipulation.
sourcefn entry_format<'a>(&'a mut self, key: &Key) -> Entry<'a>
fn entry_format<'a>(&'a mut self, key: &Key) -> Entry<'a>
Gets the given key’s corresponding entry in the Table for in-place manipulation.
sourcefn get<'s>(&'s self, key: &str) -> Option<&'s Item>
fn get<'s>(&'s self, key: &str) -> Option<&'s Item>
Returns an optional reference to an item given the key.
sourcefn get_mut<'s>(&'s mut self, key: &str) -> Option<&'s mut Item>
fn get_mut<'s>(&'s mut self, key: &str) -> Option<&'s mut Item>
Returns an optional mutable reference to an item given the key.
sourcefn get_key_value<'a>(&'a self, key: &str) -> Option<(&'a Key, &'a Item)>
fn get_key_value<'a>(&'a self, key: &str) -> Option<(&'a Key, &'a Item)>
Return references to the key-value pair stored for key, if it is present, else None.
sourcefn get_key_value_mut<'a>(
&'a mut self,
key: &str
) -> Option<(KeyMut<'a>, &'a mut Item)>
fn get_key_value_mut<'a>(
&'a mut self,
key: &str
) -> Option<(KeyMut<'a>, &'a mut Item)>
Return mutable references to the key-value pair stored for key, if it is present, else None.
sourcefn contains_key(&self, key: &str) -> bool
fn contains_key(&self, key: &str) -> bool
Returns true iff the table contains an item with the given key.
sourcefn insert(&mut self, key: &str, value: Item) -> Option<Item>
fn insert(&mut self, key: &str, value: Item) -> Option<Item>
Inserts a key-value pair into the map.
sourcefn get_values(&self) -> Vec<(Vec<&Key>, &Value)>
fn get_values(&self) -> Vec<(Vec<&Key>, &Value)>
Get key/values for values that are visually children of this table Read more
sourcefn sort_values(&mut self)
fn sort_values(&mut self)
Sorts Key/Value Pairs of the table. Read more
sourcefn is_dotted(&self) -> bool
fn is_dotted(&self) -> bool
Check if this is a wrapper for dotted keys, rather than a standard table
sourcefn set_dotted(&mut self, yes: bool)
fn set_dotted(&mut self, yes: bool)
Change this table’s dotted status
sourcefn key_decor_mut(&mut self, key: &str) -> Option<&mut Decor>
fn key_decor_mut(&mut self, key: &str) -> Option<&mut Decor>
Returns the decor associated with a given key of the table.
Auto Trait Implementations
impl RefUnwindSafe for Table
impl Send for Table
impl Sync for Table
impl Unpin for Table
impl UnwindSafe for Table
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more