Enum json::JsonValue
[−]
[src]
pub enum JsonValue { String(String), Number(f64), Boolean(bool), Null, Object(BTreeMap<String, JsonValue>), Array(Vec<JsonValue>), }
Variants
String(String)
Number(f64)
Boolean(bool)
Null
Object(BTreeMap<String, JsonValue>)
Array(Vec<JsonValue>)
Methods
impl JsonValue
[src]
fn new_object() -> JsonValue
Create an empty JsonValue::Object
instance.
When creating an object with data, consider using the object!
macro.
fn new_array() -> JsonValue
Create an empty JsonValue::Array
instance.
When creating array with data, consider using the array!
macro.
fn is<T>(&self, other: T) -> bool where T: Into<JsonValue>
Checks if the value stored matches other
.
fn is_string(&self) -> bool
fn as_string(&self) -> JsonResult<&String>
fn is_number(&self) -> bool
fn as_number(&self) -> JsonResult<&f64>
fn is_boolean(&self) -> bool
fn is_true(&self) -> bool
: please use v.is(false)
instead
fn is_false(&self) -> bool
: please use v.is(true)
instead
fn as_boolean(&self) -> JsonResult<&bool>
fn is_null(&self) -> bool
fn is_object(&self) -> bool
fn is_array(&self) -> bool
fn put<T>(&mut self, key: &str, value: T) -> JsonResult<()> where T: Into<JsonValue>
Works on JsonValue::Object
- create or override key with value.
fn get(&self, key: &str) -> JsonResult<&JsonValue>
Works on JsonValue::Object
- get a reference to a value behind key.
For most purposes consider using object[key]
instead.
fn get_mut(&mut self, key: &str) -> JsonResult<&mut JsonValue>
Works on JsonValue::Object
- get a mutable reference to a value behind
the key.
fn with(&mut self, key: &str) -> &mut JsonValue
Attempts to get a mutable reference to the value behind a key on an
object. If the reference doesn't exists, it will be created and
assigned a null. If self
is not an object, an empty object with
null key will be created.
fn push<T>(&mut self, value: T) -> JsonResult<()> where T: Into<JsonValue>
Works on JsonValue::Array
- pushes a new value to the array.
fn at(&self, index: usize) -> JsonResult<&JsonValue>
Works on JsonValue::Array
- gets a reference to a value at index.
For most purposes consider using array[index]
instead.
fn at_mut(&mut self, index: usize) -> JsonResult<&mut JsonValue>
Works on JsonValue::Array
- gets a mutable reference to a value
at index.
Trait Implementations
impl PartialEq for JsonValue
[src]
fn eq(&self, __arg_0: &JsonValue) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &JsonValue) -> bool
This method tests for !=
.
impl Debug for JsonValue
[src]
impl Index<usize> for JsonValue
[src]
Implements indexing by usize
to easily access members of an array:
let mut array = JsonValue::new_array(); array.push("foo"); assert!(array[0].is("foo"));
type Output = JsonValue
The returned type after indexing
fn index<'a>(&'a self, index: usize) -> &'a JsonValue
The method for the indexing (Foo[Bar]
) operation
impl<'b> Index<&'b str> for JsonValue
[src]
Implements indexing by &str
to easily access object members:
let mut object = JsonValue::new_object(); object.put("foo", "bar"); assert!(object["foo"].is("bar"));