Skip to content

Commit 8018a9a

Browse files
committed
Fix docs tests
1 parent 156f5d5 commit 8018a9a

File tree

1 file changed

+18
-37
lines changed

1 file changed

+18
-37
lines changed

src/raw.rs

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,10 @@ impl RawValue {
256256
/// ```
257257
/// # use serde_json::json;
258258
/// #
259-
/// let v = json!({ "a": null, "b": false });
260-
/// let v = serde_json::value::to_raw_value(v).unwrap();
259+
/// let val= json!(null);
260+
/// let val = serde_json::value::to_raw_value(&val).unwrap();
261261
///
262-
/// assert!(v["a"].is_null());
263-
///
264-
/// // The boolean `false` is not null.
265-
/// assert!(!v["b"].is_null());
262+
/// assert!(val.is_null());
266263
/// ```
267264
pub fn is_null(&self) -> bool {
268265
matches!(self.kind(), RawKind::Null)
@@ -273,13 +270,10 @@ impl RawValue {
273270
/// ```
274271
/// # use serde_json::json;
275272
/// #
276-
/// let v = json!({ "a": false, "b": "false" });
277-
/// let v = serde_json::value::to_raw_value(v).unwrap();
278-
///
279-
/// assert!(v["a"].is_boolean());
273+
/// let val = json!(true);
274+
/// let val = serde_json::value::to_raw_value(&val).unwrap();
280275
///
281-
/// // The string `"false"` is a string, not a boolean.
282-
/// assert!(!v["b"].is_boolean());
276+
/// assert!(val.is_boolean());
283277
/// ```
284278
pub fn is_boolean(&self) -> bool {
285279
matches!(self.kind(), RawKind::Bool)
@@ -290,13 +284,10 @@ impl RawValue {
290284
/// ```
291285
/// # use serde_json::json;
292286
/// #
293-
/// let v = json!({ "a": 1, "b": "2" });
294-
/// let v = serde_json::value::to_raw_value(v).unwrap();
295-
///
296-
/// assert!(v["a"].is_number());
287+
/// let val = json!(101);
288+
/// let val = serde_json::value::to_raw_value(&val).unwrap();
297289
///
298-
/// // The string `"2"` is a string, not a number.
299-
/// assert!(!v["b"].is_number());
290+
/// assert!(val.is_number());
300291
/// ```
301292
pub fn is_number(&self) -> bool {
302293
matches!(self.kind(), RawKind::Number)
@@ -307,13 +298,10 @@ impl RawValue {
307298
/// ```
308299
/// # use serde_json::json;
309300
/// #
310-
/// let v = json!({ "a": "some string", "b": false });
311-
/// let v = serde_json::value::to_raw_value(v).unwrap();
301+
/// let val = json!("some string");
302+
/// let val = serde_json::value::to_raw_value(&val).unwrap();
312303
///
313-
/// assert!(v["a"].is_string());
314-
///
315-
/// // The boolean `false` is not a string.
316-
/// assert!(!v["b"].is_string());
304+
/// assert!(val.is_string());
317305
/// ```
318306
pub fn is_string(&self) -> bool {
319307
matches!(self.kind(), RawKind::String)
@@ -324,13 +312,10 @@ impl RawValue {
324312
/// ```
325313
/// # use serde_json::json;
326314
/// #
327-
/// let obj = json!({ "a": ["an", "array"], "b": { "an": "object" } });
328-
/// let obj = serde_json::value::to_raw_value(obj).unwrap();
329-
///
330-
/// assert!(obj["a"].is_array());
315+
/// let val = json!(["an", "array"]);
316+
/// let val = serde_json::value::to_raw_value(&val).unwrap();
331317
///
332-
/// // an object, not an array
333-
/// assert!(!obj["b"].is_array());
318+
/// assert!(val.is_array());
334319
/// ```
335320
pub fn is_array(&self) -> bool {
336321
matches!(self.kind(), RawKind::Array)
@@ -341,14 +326,10 @@ impl RawValue {
341326
/// ```
342327
/// # use serde_json::json;
343328
/// #
344-
/// let obj = json!({ "a": { "nested": true }, "b": ["an", "array"] });
345-
/// let obj = serde_json::value::to_raw_value(obj).unwrap();
346-
///
347-
/// assert!(obj.is_object());
348-
/// assert!(obj["a"].is_object());
329+
/// let val = json!({ "a": { "nested": true }, "b": ["an", "array"] });
330+
/// let val = serde_json::value::to_raw_value(&val).unwrap();
349331
///
350-
/// // array, not an object
351-
/// assert!(!obj["b"].is_object());
332+
/// assert!(val.is_object());
352333
/// ```
353334
pub fn is_object(&self) -> bool {
354335
matches!(self.kind(), RawKind::Object)

0 commit comments

Comments
 (0)