}
}
- /// 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.
}
}
-/// 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 }
}
/// 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;
/// 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) => {
}
}
- /// 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),
}
}
- /// 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),
}
}
- /// 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[..]),
}
}
- /// 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,
}
}
- /// 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,
}
}
- /// 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,
}
}
- /// 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,
}
}
- /// 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),
}
}
- /// 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),
}
}
- /// 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),
}
}
- /// 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),
}
}
- /// 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(()),
/// 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.
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; }
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; }
}
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, }
}
}
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