Skip to content

Commit 521d63c

Browse files
committed
docs: Distinguish Table/InlineTable on Item
1 parent b8a207c commit 521d63c

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

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
}

0 commit comments

Comments
 (0)