Skip to content

Commit 2298715

Browse files
authored
Merge pull request #839 from epage/docs
docs: Distinguish Table/InlineTable
2 parents dc1ee5b + 3ac4d9c commit 2298715

File tree

10 files changed

+71
-45
lines changed

10 files changed

+71
-45
lines changed

crates/toml_edit/src/array.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use crate::repr::Decor;
55
use crate::value::{DEFAULT_LEADING_VALUE_DECOR, DEFAULT_VALUE_DECOR};
66
use crate::{Item, RawString, Value};
77

8-
/// Type representing a TOML array,
9-
/// payload of the `Value::Array` variant's value
8+
/// A TOML [`Value`] that contains a sequence of [`Value`]s
109
#[derive(Debug, Default, Clone)]
1110
pub struct Array {
1211
// `trailing` represents whitespaces, newlines
@@ -20,11 +19,11 @@ pub struct Array {
2019
pub(crate) values: Vec<Item>,
2120
}
2221

23-
/// An owned iterator type over `Table`'s key/value pairs.
22+
/// An owned iterator type over [`Array`]'s [`Value`]s
2423
pub type ArrayIntoIter = Box<dyn Iterator<Item = Value>>;
25-
/// An iterator type over `Array`'s values.
24+
/// An iterator type over [`Array`]'s [`Value`]s
2625
pub type ArrayIter<'a> = Box<dyn Iterator<Item = &'a Value> + 'a>;
27-
/// An iterator type over `Array`'s values.
26+
/// An iterator type over [`Array`]'s [`Value`]s
2827
pub type ArrayIterMut<'a> = Box<dyn Iterator<Item = &'a mut Value> + 'a>;
2928

3029
/// Constructors

crates/toml_edit/src/array_of_tables.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::iter::FromIterator;
22

33
use crate::{Array, Item, Table};
44

5-
/// Type representing a TOML array of tables
5+
/// A top-level sequence of [`Table`]s, each under their own header
66
#[derive(Clone, Debug, Default)]
77
pub struct ArrayOfTables {
88
// Always Vec<Item::Table>, just `Item` to make `Index` work
@@ -109,11 +109,11 @@ impl ArrayOfTables {
109109
}
110110
}
111111

112-
/// An iterator type over `ArrayOfTables`'s values.
112+
/// An iterator type over [`ArrayOfTables`]'s [`Table`]s
113113
pub type ArrayOfTablesIter<'a> = Box<dyn Iterator<Item = &'a Table> + 'a>;
114-
/// An iterator type over `ArrayOfTables`'s values.
114+
/// An iterator type over [`ArrayOfTables`]'s [`Table`]s
115115
pub type ArrayOfTablesIterMut<'a> = Box<dyn Iterator<Item = &'a mut Table> + 'a>;
116-
/// An iterator type over `ArrayOfTables`'s values.
116+
/// An iterator type over [`ArrayOfTables`]'s [`Table`]s
117117
pub type ArrayOfTablesIntoIter = Box<dyn Iterator<Item = Table>>;
118118

119119
impl Extend<Table> for ArrayOfTables {

crates/toml_edit/src/document.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::str::FromStr;
33
use crate::table::Iter;
44
use crate::{Item, RawString, Table};
55

6-
/// Type representing a parsed TOML document
6+
/// The root TOML [`Table`], containing [`Key`][crate::Key]/[`Value`][crate::Value] pairs and all other logic [`Table`]s
77
#[derive(Debug, Clone)]
88
pub struct ImDocument<S> {
99
pub(crate) root: Item,
@@ -105,7 +105,7 @@ impl<S> std::ops::Deref for ImDocument<S> {
105105
}
106106
}
107107

108-
/// Type representing a TOML document
108+
/// The editable root TOML [`Table`], containing [`Key`][crate::Key]/[`Value`][crate::Value] pairs and all other logic [`Table`]s
109109
#[derive(Debug, Clone)]
110110
pub struct DocumentMut {
111111
pub(crate) root: Item,

crates/toml_edit/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::error::Error as StdError;
22
use std::fmt::{Display, Formatter, Result};
33

4-
/// Type representing a TOML parse error
4+
/// A TOML parse error
55
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
66
pub struct TomlError {
77
message: String,

crates/toml_edit/src/inline_table.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use crate::repr::Decor;
55
use crate::table::{Iter, IterMut, KeyValuePairs, TableLike};
66
use crate::{InternalString, Item, KeyMut, RawString, Table, Value};
77

8-
/// Type representing a TOML inline table,
9-
/// payload of the `Value::InlineTable` variant
8+
/// A TOML [`Value`] that contains a collection of [`Key`]/[`Value`] pairs
109
#[derive(Debug, Default, Clone)]
1110
pub struct InlineTable {
1211
// `preamble` represents whitespaces in an empty table
@@ -511,11 +510,11 @@ fn decorate_inline_table(table: &mut InlineTable) {
511510
}
512511
}
513512

514-
/// An owned iterator type over key/value pairs of an inline table.
513+
/// An owned iterator type over an [`InlineTable`]'s [`Key`]/[`Value`] pairs
515514
pub type InlineTableIntoIter = Box<dyn Iterator<Item = (InternalString, Value)>>;
516-
/// An iterator type over key/value pairs of an inline table.
515+
/// An iterator type over [`InlineTable`]'s [`Key`]/[`Value`] pairs
517516
pub type InlineTableIter<'a> = Box<dyn Iterator<Item = (&'a str, &'a Value)> + 'a>;
518-
/// A mutable iterator type over key/value pairs of an inline table.
517+
/// A mutable iterator type over [`InlineTable`]'s [`Key`]/[`Value`] pairs
519518
pub type InlineTableIterMut<'a> = Box<dyn Iterator<Item = (KeyMut<'a>, &'a mut Value)> + 'a>;
520519

521520
impl TableLike for InlineTable {
@@ -613,7 +612,7 @@ impl TableLike for InlineTable {
613612
// `{ key1 = value1, ... }`
614613
pub(crate) const DEFAULT_INLINE_KEY_DECOR: (&str, &str) = (" ", " ");
615614

616-
/// A view into a single location in a map, which may be vacant or occupied.
615+
/// A view into a single location in an [`InlineTable`], which may be vacant or occupied.
617616
pub enum InlineEntry<'a> {
618617
/// An occupied Entry.
619618
Occupied(InlineOccupiedEntry<'a>),
@@ -659,7 +658,7 @@ impl<'a> InlineEntry<'a> {
659658
}
660659
}
661660

662-
/// A view into a single occupied location in a `IndexMap`.
661+
/// A view into a single occupied location in an [`InlineTable`].
663662
pub struct InlineOccupiedEntry<'a> {
664663
entry: indexmap::map::OccupiedEntry<'a, Key, Item>,
665664
}
@@ -714,7 +713,7 @@ impl<'a> InlineOccupiedEntry<'a> {
714713
}
715714
}
716715

717-
/// A view into a single empty location in a `IndexMap`.
716+
/// A view into a single empty location in an [`InlineTable`].
718717
pub struct InlineVacantEntry<'a> {
719718
entry: indexmap::map::VacantEntry<'a, Key, Item>,
720719
}

crates/toml_edit/src/item.rs

+36-12
Original file line numberDiff line numberDiff line change
@@ -72,49 +72,61 @@ impl Item {
7272
index.index_mut(self)
7373
}
7474

75-
/// Casts `self` to value.
75+
/// Casts `self` to [`Value`]
7676
pub fn as_value(&self) -> Option<&Value> {
7777
match *self {
7878
Item::Value(ref v) => Some(v),
7979
_ => None,
8080
}
8181
}
82-
/// Casts `self` to table.
82+
/// Casts `self` to [`Table`]
83+
///
84+
/// <div class="warning">
85+
///
86+
/// To operate on both [`Table`]s and [`InlineTable`]s, see [`Item::as_table_like`]
87+
///
88+
/// </div>
8389
pub fn as_table(&self) -> Option<&Table> {
8490
match *self {
8591
Item::Table(ref t) => Some(t),
8692
_ => None,
8793
}
8894
}
89-
/// Casts `self` to array of tables.
95+
/// Casts `self` to [`ArrayOfTables`]
9096
pub fn as_array_of_tables(&self) -> Option<&ArrayOfTables> {
9197
match *self {
9298
Item::ArrayOfTables(ref a) => Some(a),
9399
_ => None,
94100
}
95101
}
96-
/// Casts `self` to mutable value.
102+
/// Casts `self` to mutable [`Value`].
97103
pub fn as_value_mut(&mut self) -> Option<&mut Value> {
98104
match *self {
99105
Item::Value(ref mut v) => Some(v),
100106
_ => None,
101107
}
102108
}
103-
/// Casts `self` to mutable table.
109+
/// Casts `self` to mutable [`Table`]
110+
///
111+
/// <div class="warning">
112+
///
113+
/// To operate on both [`Table`]s and [`InlineTable`]s, see [`Item::as_table_like_mut`]
114+
///
115+
/// </div>
104116
pub fn as_table_mut(&mut self) -> Option<&mut Table> {
105117
match *self {
106118
Item::Table(ref mut t) => Some(t),
107119
_ => None,
108120
}
109121
}
110-
/// Casts `self` to mutable array of tables.
122+
/// Casts `self` to mutable [`ArrayOfTables`]
111123
pub fn as_array_of_tables_mut(&mut self) -> Option<&mut ArrayOfTables> {
112124
match *self {
113125
Item::ArrayOfTables(ref mut a) => Some(a),
114126
_ => None,
115127
}
116128
}
117-
/// Casts `self` to value.
129+
/// Casts `self` to [`Value`]
118130
pub fn into_value(self) -> Result<Value, Self> {
119131
match self {
120132
Item::None => Err(self),
@@ -135,15 +147,21 @@ impl Item {
135147
let other = other.into_value().map(Item::Value).unwrap_or(Item::None);
136148
*self = other;
137149
}
138-
/// Casts `self` to table.
150+
/// Casts `self` to [`Table`]
151+
///
152+
/// <div class="warning">
153+
///
154+
/// This does not include [`InlineTable`]s
155+
///
156+
/// </div>
139157
pub fn into_table(self) -> Result<Table, Self> {
140158
match self {
141159
Item::Table(t) => Ok(t),
142160
Item::Value(Value::InlineTable(t)) => Ok(t.into_table()),
143161
_ => Err(self),
144162
}
145163
}
146-
/// Casts `self` to array of tables.
164+
/// Casts `self` to [`ArrayOfTables`]
147165
pub fn into_array_of_tables(self) -> Result<ArrayOfTables, Self> {
148166
match self {
149167
Item::ArrayOfTables(a) => Ok(a),
@@ -177,15 +195,21 @@ impl Item {
177195
};
178196
*self = other;
179197
}
180-
/// Returns true if `self` is a value.
198+
/// Returns true if `self` is a [`Value`]
181199
pub fn is_value(&self) -> bool {
182200
self.as_value().is_some()
183201
}
184-
/// Returns true if `self` is a table.
202+
/// Returns true if `self` is a [`Table`]
203+
///
204+
/// <div class="warning">
205+
///
206+
/// To operate on both [`Table`]s and [`InlineTable`]s, see [`Item::is_table_like`]
207+
///
208+
/// </div>
185209
pub fn is_table(&self) -> bool {
186210
self.as_table().is_some()
187211
}
188-
/// Returns true if `self` is an array of tables.
212+
/// Returns true if `self` is an [`ArrayOfTables`]
189213
pub fn is_array_of_tables(&self) -> bool {
190214
self.as_array_of_tables().is_some()
191215
}

crates/toml_edit/src/key.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use std::str::FromStr;
44
use crate::repr::{Decor, Repr};
55
use crate::InternalString;
66

7-
/// Key as part of a Key/Value Pair or a table header.
7+
/// For Key/[`Value`][crate::Value] pairs under a [`Table`][crate::Table] header or inside an
8+
/// [`InlineTable`][crate::InlineTable]
89
///
910
/// # Examples
1011
///
@@ -333,7 +334,7 @@ impl From<Key> for InternalString {
333334
}
334335
}
335336

336-
/// A mutable reference to a `Key`'s formatting
337+
/// A mutable reference to a [`Key`]'s formatting
337338
#[derive(Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
338339
pub struct KeyMut<'k> {
339340
key: &'k mut Key,

crates/toml_edit/src/repr.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::borrow::Cow;
22

33
use crate::RawString;
44

5-
/// A value together with its `to_string` representation,
6-
/// including surrounding it whitespaces and comments.
5+
/// A scalar TOML [`Value`][crate::Value]'s logical value and its representation in a `&str`
6+
///
7+
/// This includes the surrounding whitespace and comments.
78
#[derive(Eq, PartialEq, Clone, Hash)]
89
pub struct Formatted<T> {
910
value: T,
@@ -134,7 +135,7 @@ mod inner {
134135
impl ValueRepr for toml_datetime::Datetime {}
135136
}
136137

137-
/// TOML-encoded value
138+
/// A TOML [`Value`][crate::Value] encoded as a `&str`
138139
#[derive(Eq, PartialEq, Clone, Hash)]
139140
pub struct Repr {
140141
raw_value: RawString,

crates/toml_edit/src/table.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use crate::repr::Decor;
77
use crate::value::DEFAULT_VALUE_DECOR;
88
use crate::{InlineTable, InternalString, Item, KeyMut, Value};
99

10-
/// Type representing a TOML non-inline table
10+
/// A TOML table, a top-level collection of key/[`Value`] pairs under a header and logical
11+
/// sub-tables
1112
#[derive(Clone, Debug, Default)]
1213
pub struct Table {
1314
// Comments/spaces before and after the header
@@ -524,11 +525,11 @@ pub(crate) const DEFAULT_KEY_DECOR: (&str, &str) = ("", " ");
524525
pub(crate) const DEFAULT_TABLE_DECOR: (&str, &str) = ("\n", "");
525526
pub(crate) const DEFAULT_KEY_PATH_DECOR: (&str, &str) = ("", "");
526527

527-
/// An owned iterator type over `Table`'s key/value pairs.
528+
/// An owned iterator type over [`Table`]'s [`Key`]/[`Item`] pairs
528529
pub type IntoIter = Box<dyn Iterator<Item = (InternalString, Item)>>;
529-
/// An iterator type over `Table`'s key/value pairs.
530+
/// An iterator type over [`Table`]'s [`Key`]/[`Item`] pairs
530531
pub type Iter<'a> = Box<dyn Iterator<Item = (&'a str, &'a Item)> + 'a>;
531-
/// A mutable iterator type over `Table`'s key/value pairs.
532+
/// A mutable iterator type over [`Table`]'s [`Key`]/[`Item`] pairs
532533
pub type IterMut<'a> = Box<dyn Iterator<Item = (KeyMut<'a>, &'a mut Item)> + 'a>;
533534

534535
/// This trait represents either a `Table`, or an `InlineTable`.
@@ -664,7 +665,7 @@ impl TableLike for Table {
664665
}
665666
}
666667

667-
/// A view into a single location in a map, which may be vacant or occupied.
668+
/// A view into a single location in a [`Table`], which may be vacant or occupied.
668669
pub enum Entry<'a> {
669670
/// An occupied Entry.
670671
Occupied(OccupiedEntry<'a>),
@@ -710,7 +711,7 @@ impl<'a> Entry<'a> {
710711
}
711712
}
712713

713-
/// A view into a single occupied location in a `IndexMap`.
714+
/// A view into a single occupied location in a [`Table`].
714715
pub struct OccupiedEntry<'a> {
715716
pub(crate) entry: indexmap::map::OccupiedEntry<'a, Key, Item>,
716717
}
@@ -764,7 +765,7 @@ impl<'a> OccupiedEntry<'a> {
764765
}
765766
}
766767

767-
/// A view into a single empty location in a `IndexMap`.
768+
/// A view into a single empty location in a [`Table`].
768769
pub struct VacantEntry<'a> {
769770
pub(crate) entry: indexmap::map::VacantEntry<'a, Key, Item>,
770771
}

crates/toml_edit/src/value.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use crate::key::Key;
77
use crate::repr::{Decor, Formatted};
88
use crate::{Array, InlineTable, InternalString, RawString};
99

10-
/// Representation of a TOML Value (as part of a Key/Value Pair).
10+
/// For [`Key`]/Value pairs under a [`Table`][crate::Table] header or inside another
11+
/// Value
1112
#[derive(Debug, Clone)]
1213
pub enum Value {
1314
/// A string value.

0 commit comments

Comments
 (0)