Enum json_api::value::Value
[−]
[src]
pub enum Value {
Null,
Array(Vec<Value>),
Bool(bool),
Number(Number),
Object(Map),
String(String),
}Represents any valid JSON API value.
Like serde_json::Value, but with spec compliance baked into the type
system.
Variants
NullA null value.
Array(Vec<Value>)An array of values.
Bool(bool)A boolean value.
Number(Number)An integer or floating point value.
Object(Map)A JSON object as a hash table with consistent order. Keys are guarenteed to be a valid member name.
String(String)A string value.
Methods
impl Value[src]
fn as_array(&self) -> Option<&[Value]>[src]
Optionally get the underlying vector as a slice. Returns None if the
Value is not an array.
Example
let data = vec![true.into(), false.into()]; let array = Value::Array(data.clone()); let boolean = Value::Bool(true); assert_eq!(array.as_array(), Some(data.as_slice())); assert_eq!(boolean.as_array(), None);
fn as_array_mut(&mut self) -> Option<&mut [Value]>[src]
Optionally get the underlying vector as a mutable slice. Returns None
if the Value is not an array.
Example
let mut data = vec![true.into(), false.into()]; let mut array = Value::Array(data.clone()); let mut boolean = Value::Bool(true); assert_eq!(array.as_array_mut(), Some(data.as_mut_slice())); assert_eq!(boolean.as_array_mut(), None);
fn as_bool(&self) -> Option<bool>[src]
Optionally get the inner boolean value. Returns None if the Value is
not a boolean.
Example
let boolean = Value::Bool(true); let number = Value::from(3.14); assert_eq!(boolean.as_bool(), Some(true)); assert_eq!(number.as_bool(), None);
fn as_null(&self) -> Option<()>[src]
Returns Some(()) if the Value is null.
Example
let null = Value::Null; let text = Value::String("Hello, World!".to_owned()); assert_eq!(null.as_null(), Some(())); assert_eq!(text.as_null(), None);
fn as_object(&self) -> Option<&Map>[src]
Optionally get a reference to the inner map. Returns None if the
Value is not an object.
Example
let data = Map::new(); let object = Value::Object(data.clone()); let number = Value::from(3.14); assert_eq!(object.as_object(), Some(&data)); assert_eq!(number.as_object(), None);
fn as_object_mut(&mut self) -> Option<&mut Map>[src]
Optionally get a mutable reference to the inner map. Returns None if
the Value is not an object.
Example
let mut data = Map::new(); let mut object = Value::Object(data.clone()); let mut number = Value::from(3.14); assert_eq!(object.as_object_mut(), Some(&mut data)); assert_eq!(number.as_object_mut(), None);
fn as_str(&self) -> Option<&str>[src]
Optionally get the underlying string as a string slice. Returns None
if the Value is not a string.
Example
let data = "Hello, World!"; let string = Value::String(data.to_owned()); let number = Value::from(3.14); assert_eq!(string.as_str(), Some(data)); assert_eq!(number.as_str(), None);
fn as_f64(&self) -> Option<f64>[src]
Optionally get the underlying number as an f64. Returns None if the
Value cannot be represented as an f64.
Example
let number = Value::from(3.14); let string = Value::String("Hello, World!".to_owned()); assert_eq!(number.as_f64(), Some(3.14)); assert_eq!(string.as_f64(), None);
fn as_i64(&self) -> Option<i64>[src]
Optionally get the underlying number as an i64. Returns None if the
Value cannot be represented as an i64.
Example
let integer = Value::from(10); let float = Value::from(3.14); assert_eq!(integer.as_i64(), Some(10)); assert_eq!(float.as_i64(), None);
fn as_u64(&self) -> Option<u64>[src]
Optionally get the underlying number as an u64. Returns None if the
Value cannot be represented as an u64.
Example
let positive = Value::from(10); let negative = Value::from(-10); assert_eq!(positive.as_u64(), Some(10)); assert_eq!(negative.as_u64(), None);
fn is_array(&self) -> bool[src]
Returns true if the Value is an array.
For any Value on which is_array returns true, as_array and
as_array_mut are guaranteed to return a reference to the vector
representing the array.
Example
let mut value = Value::from(vec![1, 2, 3]); assert!(value.is_array()); value.as_array().unwrap(); value.as_array_mut().unwrap();
fn is_boolean(&self) -> bool[src]
Returns true if the Value is a boolean.
For any Value on which is_boolean returns true, as_bool is
guaranteed to return the boolean value.
Example
let value = Value::Bool(true); assert!(value.is_boolean()); value.as_bool().unwrap();
fn is_null(&self) -> bool[src]
Returns true if the Value is null.
For any Value on which is_null returns true, as_null is
guaranteed to return Some(()).
Example
let value = Value::Null; assert!(value.is_null()); value.as_null().unwrap();
fn is_number(&self) -> bool[src]
fn is_object(&self) -> bool[src]
Returns true if the Value is an object.
For any Value on which is_array returns true, as_object and
as_object_mut are guaranteed to return a reference to the map
representing the object.
Example
let mut value = Value::Object(Default::default()); assert!(value.is_object()); value.as_object().unwrap(); value.as_object_mut().unwrap();
fn is_string(&self) -> bool[src]
Returns true if the Value is a string.
For any Value on which is_string returns true, as_str is
guaranteed to return the string slice.
Example
let value = Value::String("Hello, world!".to_owned()); assert!(value.is_string()); value.as_str().unwrap();
fn is_f64(&self) -> bool[src]
Returns true if the Value is a number that can be represented as an
f64.
For any Value on which is_f64 returns true, as_f64 is
guaranteed to return the floating point value.
Currently this function returns true if and only if both is_i64 and
is_u64 return false. This behavior is not a guarantee in the future.
Example
let value = Value::from(3.14); assert!(value.is_f64()); value.as_f64().unwrap();
fn is_i64(&self) -> bool[src]
Returns true if the Value is an integer between i64::MIN and
i64::MAX.
For any Value on which is_i64 returns true, as_i64 is guaranteed
to return the integer value.
Example
let pos = Value::from(3); let neg = Value::from(-3); assert!(pos.is_i64()); assert!(neg.is_i64()); pos.as_i64().unwrap(); neg.as_i64().unwrap();
fn is_u64(&self) -> bool[src]
Trait Implementations
impl Clone for Value[src]
fn clone(&self) -> Value[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl Debug for Value[src]
impl PartialEq for Value[src]
fn eq(&self, __arg_0: &Value) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &Value) -> bool[src]
This method tests for !=.
impl Default for Value[src]
Returns the Value::Null. This allows for better composition with Option
types.
Example
const MSG: &'static str = "Hello, World!"; let opt = None; let value = opt.map(Value::String).unwrap_or_default(); assert_eq!(value, Value::Null); let opt = Some(MSG.to_owned()); let value = opt.map(Value::String).unwrap_or_default(); assert_eq!(value, Value::String(MSG.to_owned()));
impl From<bool> for Value[src]
impl From<f32> for Value[src]
impl From<f64> for Value[src]
impl From<i8> for Value[src]
impl From<i16> for Value[src]
impl From<i32> for Value[src]
impl From<i64> for Value[src]
impl From<u8> for Value[src]
impl From<u16> for Value[src]
impl From<u32> for Value[src]
impl From<u64> for Value[src]
impl From<String> for Value[src]
impl From<Map> for Value[src]
impl<T> From<Option<T>> for Value where
T: Into<Value>, [src]
T: Into<Value>,
impl<T> From<Vec<T>> for Value where
T: Into<Value>, [src]
T: Into<Value>,
impl<'a> From<&'a str> for Value[src]
impl<'a, T> From<&'a [T]> for Value where
T: Clone + Into<Value>, [src]
T: Clone + Into<Value>,
impl<T> FromIterator<T> for Value where
T: Into<Value>, [src]
T: Into<Value>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>, [src]
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more
impl FromIterator<(Key, Value)> for Value[src]
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (Key, Value)>, [src]
I: IntoIterator<Item = (Key, Value)>,
Creates a value from an iterator. Read more
impl FromStr for Value[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(src: &str) -> Result<Self, Self::Err>[src]
Parses a string s to return a value of this type. Read more
impl PartialEq<bool> for Value[src]
fn eq(&self, rhs: &bool) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<f32> for Value[src]
fn eq(&self, rhs: &f32) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<f64> for Value[src]
fn eq(&self, rhs: &f64) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<i8> for Value[src]
fn eq(&self, rhs: &i8) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<i16> for Value[src]
fn eq(&self, rhs: &i16) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<i32> for Value[src]
fn eq(&self, rhs: &i32) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<i64> for Value[src]
fn eq(&self, rhs: &i64) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<isize> for Value[src]
fn eq(&self, rhs: &isize) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<u8> for Value[src]
fn eq(&self, rhs: &u8) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<u16> for Value[src]
fn eq(&self, rhs: &u16) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<u32> for Value[src]
fn eq(&self, rhs: &u32) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<u64> for Value[src]
fn eq(&self, rhs: &u64) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<usize> for Value[src]
fn eq(&self, rhs: &usize) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl PartialEq<str> for Value[src]
fn eq(&self, rhs: &str) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl<'de> Deserialize<'de> for Value[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>, [src]
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more