Skip to content

Commit 34478c6

Browse files
committed
Add Value::as_list(), as_list_mut(), and is_list()
- Use "list" instead of "array" in method names which is the terminology in the spec. - as_array(), as_array_mut(), and is_array() are treated as alternative method names. While they could be deprecated, there is no harm is keeping them. It is extremely unlikely that the spec will change to add an array vs list encoding.
1 parent f24512f commit 34478c6

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/value.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,24 +174,42 @@ impl Value {
174174
}
175175
}
176176

177-
/// If the value is an array, returns a reference to the underlying value.
177+
/// If the value is a list, returns a reference to the underlying value.
178178
#[must_use]
179-
pub fn as_array(&self) -> Option<&Vec<Value>> {
179+
pub fn as_list(&self) -> Option<&Vec<Value>> {
180180
match self {
181181
Value::List(ref l) => Some(l),
182182
_ => None,
183183
}
184184
}
185185

186-
/// If the value is an array, returns a mutable reference to the underlying value.
186+
/// If the value is a list, returns a mutable reference to the underlying value.
187187
#[must_use]
188-
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>> {
188+
pub fn as_list_mut(&mut self) -> Option<&mut Vec<Value>> {
189189
match self {
190190
Value::List(ref mut l) => Some(l),
191191
_ => None,
192192
}
193193
}
194194

195+
/// If the value is a list, returns a reference to the underlying value.
196+
///
197+
/// Alternative method name for [Value::as_list()].
198+
#[inline]
199+
#[must_use]
200+
pub fn as_array(&self) -> Option<&Vec<Value>> {
201+
self.as_list()
202+
}
203+
204+
/// If the value is a list, returns a mutable reference to the underlying value.
205+
///
206+
/// Alternative method name for [Value::as_list_mut()].
207+
#[inline]
208+
#[must_use]
209+
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>> {
210+
self.as_list_mut()
211+
}
212+
195213
/// If the value is a dictionary, returns a reference to the underlying value.
196214
#[must_use]
197215
pub fn as_dict(&self) -> Option<&BTreeMap<ByteString, Value>> {
@@ -240,10 +258,18 @@ impl Value {
240258
self.as_i64().is_some()
241259
}
242260

243-
/// Returns true if the value is an array.
261+
/// Returns true if the value is a list.
262+
#[must_use]
263+
pub fn is_list(&self) -> bool {
264+
self.as_list().is_some()
265+
}
266+
267+
/// Returns true if the value is a list.
268+
///
269+
/// Alternative method name for [Value::is_list()].
244270
#[must_use]
245271
pub fn is_array(&self) -> bool {
246-
self.as_array().is_some()
272+
self.is_list()
247273
}
248274

249275
/// Returns true if the value is a dictionary.

0 commit comments

Comments
 (0)