]> git.lizzy.rs Git - rust.git/blobdiff - src/libserialize/json.rs
Rollup merge of #60766 - vorner:weak-into-raw, r=sfackler
[rust.git] / src / libserialize / json.rs
index 5b3444b9f456f33d94ac14f6db30bb8faa26d144..a4fd28845120542adbf78a469fb520f922b5f7e6 100644 (file)
@@ -716,7 +716,7 @@ pub fn new(writer: &'a mut dyn fmt::Write) -> PrettyEncoder<'a> {
         }
     }
 
-    /// Set the number of spaces to indent for each level.
+    /// Sets the number of spaces to indent for each level.
     /// This is safe to set during encoding.
     pub fn set_indent(&mut self, indent: usize) {
         // self.indent very well could be 0 so we need to use checked division.
@@ -1010,13 +1010,13 @@ fn encode<E: crate::Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
     }
 }
 
-/// Create an `AsJson` wrapper which can be used to print a value as JSON
+/// Creates an `AsJson` wrapper which can be used to print a value as JSON
 /// on-the-fly via `write!`
 pub fn as_json<T>(t: &T) -> AsJson<'_, T> {
     AsJson { inner: t }
 }
 
-/// Create an `AsPrettyJson` wrapper which can be used to print a value as JSON
+/// Creates an `AsPrettyJson` wrapper which can be used to print a value as JSON
 /// on-the-fly via `write!`
 pub fn as_pretty_json<T>(t: &T) -> AsPrettyJson<'_, T> {
     AsPrettyJson { inner: t, indent: None }
@@ -1039,7 +1039,7 @@ pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{
     }
 
     /// Attempts to get a nested Json Object for each key in `keys`.
-    /// If any key is found not to exist, find_path will return None.
+    /// If any key is found not to exist, `find_path` will return `None`.
     /// Otherwise, it will return the Json value associated with the final key.
     pub fn find_path<'a>(&'a self, keys: &[&str]) -> Option<&'a Json>{
         let mut target = self;
@@ -1051,7 +1051,7 @@ pub fn find_path<'a>(&'a self, keys: &[&str]) -> Option<&'a Json>{
 
     /// If the Json value is an Object, performs a depth-first search until
     /// a value associated with the provided key is found. If no value is found
-    /// or the Json value is not an Object, returns None.
+    /// or the Json value is not an Object, returns `None`.
     pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> {
         match self {
             &Json::Object(ref map) => {
@@ -1072,13 +1072,13 @@ pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> {
         }
     }
 
-    /// Returns true if the Json value is an Object. Returns false otherwise.
+    /// Returns `true` if the Json value is an `Object`.
     pub fn is_object(&self) -> bool {
         self.as_object().is_some()
     }
 
-    /// If the Json value is an Object, returns the associated BTreeMap.
-    /// Returns None otherwise.
+    /// If the Json value is an `Object`, returns the associated `BTreeMap`;
+    /// returns `None` otherwise.
     pub fn as_object(&self) -> Option<&Object> {
         match *self {
             Json::Object(ref map) => Some(map),
@@ -1086,13 +1086,13 @@ pub fn as_object(&self) -> Option<&Object> {
         }
     }
 
-    /// Returns true if the Json value is an Array. Returns false otherwise.
+    /// Returns `true` if the Json value is an `Array`.
     pub fn is_array(&self) -> bool {
         self.as_array().is_some()
     }
 
-    /// If the Json value is an Array, returns the associated vector.
-    /// Returns None otherwise.
+    /// If the Json value is an `Array`, returns the associated vector;
+    /// returns `None` otherwise.
     pub fn as_array(&self) -> Option<&Array> {
         match *self {
             Json::Array(ref array) => Some(&*array),
@@ -1100,13 +1100,13 @@ pub fn as_array(&self) -> Option<&Array> {
         }
     }
 
-    /// Returns true if the Json value is a String. Returns false otherwise.
+    /// Returns `true` if the Json value is a `String`.
     pub fn is_string(&self) -> bool {
         self.as_string().is_some()
     }
 
-    /// If the Json value is a String, returns the associated str.
-    /// Returns None otherwise.
+    /// If the Json value is a `String`, returns the associated `str`;
+    /// returns `None` otherwise.
     pub fn as_string(&self) -> Option<&str> {
         match *self {
             Json::String(ref s) => Some(&s[..]),
@@ -1114,7 +1114,7 @@ pub fn as_string(&self) -> Option<&str> {
         }
     }
 
-    /// Returns true if the Json value is a Number. Returns false otherwise.
+    /// Returns `true` if the Json value is a `Number`.
     pub fn is_number(&self) -> bool {
         match *self {
             Json::I64(_) | Json::U64(_) | Json::F64(_) => true,
@@ -1122,7 +1122,7 @@ pub fn is_number(&self) -> bool {
         }
     }
 
-    /// Returns true if the Json value is a i64. Returns false otherwise.
+    /// Returns `true` if the Json value is a `i64`.
     pub fn is_i64(&self) -> bool {
         match *self {
             Json::I64(_) => true,
@@ -1130,7 +1130,7 @@ pub fn is_i64(&self) -> bool {
         }
     }
 
-    /// Returns true if the Json value is a u64. Returns false otherwise.
+    /// Returns `true` if the Json value is a `u64`.
     pub fn is_u64(&self) -> bool {
         match *self {
             Json::U64(_) => true,
@@ -1138,7 +1138,7 @@ pub fn is_u64(&self) -> bool {
         }
     }
 
-    /// Returns true if the Json value is a f64. Returns false otherwise.
+    /// Returns `true` if the Json value is a `f64`.
     pub fn is_f64(&self) -> bool {
         match *self {
             Json::F64(_) => true,
@@ -1146,8 +1146,8 @@ pub fn is_f64(&self) -> bool {
         }
     }
 
-    /// If the Json value is a number, return or cast it to a i64.
-    /// Returns None otherwise.
+    /// If the Json value is a number, returns or cast it to a `i64`;
+    /// returns `None` otherwise.
     pub fn as_i64(&self) -> Option<i64> {
         match *self {
             Json::I64(n) => Some(n),
@@ -1156,8 +1156,8 @@ pub fn as_i64(&self) -> Option<i64> {
         }
     }
 
-    /// If the Json value is a number, return or cast it to a u64.
-    /// Returns None otherwise.
+    /// If the Json value is a number, returns or cast it to a `u64`;
+    /// returns `None` otherwise.
     pub fn as_u64(&self) -> Option<u64> {
         match *self {
             Json::I64(n) => Some(n as u64),
@@ -1166,8 +1166,8 @@ pub fn as_u64(&self) -> Option<u64> {
         }
     }
 
-    /// If the Json value is a number, return or cast it to a f64.
-    /// Returns None otherwise.
+    /// If the Json value is a number, returns or cast it to a `f64`;
+    /// returns `None` otherwise.
     pub fn as_f64(&self) -> Option<f64> {
         match *self {
             Json::I64(n) => Some(n as f64),
@@ -1177,13 +1177,13 @@ pub fn as_f64(&self) -> Option<f64> {
         }
     }
 
-    /// Returns true if the Json value is a Boolean. Returns false otherwise.
+    /// Returns `true` if the Json value is a `Boolean`.
     pub fn is_boolean(&self) -> bool {
         self.as_boolean().is_some()
     }
 
-    /// If the Json value is a Boolean, returns the associated bool.
-    /// Returns None otherwise.
+    /// If the Json value is a `Boolean`, returns the associated `bool`;
+    /// returns `None` otherwise.
     pub fn as_boolean(&self) -> Option<bool> {
         match *self {
             Json::Boolean(b) => Some(b),
@@ -1191,13 +1191,13 @@ pub fn as_boolean(&self) -> Option<bool> {
         }
     }
 
-    /// Returns true if the Json value is a Null. Returns false otherwise.
+    /// Returns `true` if the Json value is a `Null`.
     pub fn is_null(&self) -> bool {
         self.as_null().is_some()
     }
 
-    /// If the Json value is a Null, returns ().
-    /// Returns None otherwise.
+    /// If the Json value is a `Null`, returns `()`;
+    /// returns `None` otherwise.
     pub fn as_null(&self) -> Option<()> {
         match *self {
             Json::Null => Some(()),
@@ -1293,7 +1293,7 @@ pub fn new() -> Stack {
     /// Returns The number of elements in the Stack.
     pub fn len(&self) -> usize { self.stack.len() }
 
-    /// Returns true if the stack is empty.
+    /// Returns `true` if the stack is empty.
     pub fn is_empty(&self) -> bool { self.stack.is_empty() }
 
     /// Provides access to the StackElement at a given index.
@@ -1319,7 +1319,7 @@ pub fn is_equal_to(&self, rhs: &[StackElement<'_>]) -> bool {
         true
     }
 
-    /// Returns true if the bottom-most elements of this stack are the same as
+    /// Returns `true` if the bottom-most elements of this stack are the same as
     /// the ones passed as parameter.
     pub fn starts_with(&self, rhs: &[StackElement<'_>]) -> bool {
         if self.stack.len() < rhs.len() { return false; }
@@ -1329,7 +1329,7 @@ pub fn starts_with(&self, rhs: &[StackElement<'_>]) -> bool {
         true
     }
 
-    /// Returns true if the top-most elements of this stack are the same as
+    /// Returns `true` if the top-most elements of this stack are the same as
     /// the ones passed as parameter.
     pub fn ends_with(&self, rhs: &[StackElement<'_>]) -> bool {
         if self.stack.len() < rhs.len() { return false; }
@@ -1954,7 +1954,7 @@ pub struct Builder<T> {
 }
 
 impl<T: Iterator<Item=char>> Builder<T> {
-    /// Create a JSON Builder.
+    /// Creates a JSON Builder.
     pub fn new(src: T) -> Builder<T> {
         Builder { parser: Parser::new(src), token: None, }
     }
@@ -2552,7 +2552,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 }
 
 impl<'a, T> AsPrettyJson<'a, T> {
-    /// Set the indentation level for the emitted JSON
+    /// Sets the indentation level for the emitted JSON
     pub fn indent(mut self, indent: usize) -> AsPrettyJson<'a, T> {
         self.indent = Some(indent);
         self