Enum xmlrpc::Value
[−]
[src]
pub enum Value { Int(i32), Int64(i64), Bool(bool), String(String), Double(f64), DateTime(DateTime), Base64(Vec<u8>), Struct(BTreeMap<String, Value>), Array(Vec<Value>), Nil, }
The possible XML-RPC values.
Nested values can be accessed by using get
method and Rust's square-bracket
indexing operator.
A string index can be used to access a value in a Struct
, and a usize
index can be used to
access an element of an Array
.
Examples
let nothing = Value::Nil; let person = Value::Struct(vec![ ("name".to_string(), Value::from("John Doe")), ("age".to_string(), Value::from(37)), ("children".to_string(), Value::Array(vec![ Value::from("Mark"), Value::from("Jennyfer") ])), ].into_iter().collect()); // get assert_eq!(nothing.get("name"), None); assert_eq!(person.get("name"), Some(&Value::from("John Doe"))); assert_eq!(person.get("SSN"), None); // index assert_eq!(nothing["name"], Value::Nil); assert_eq!(person["name"], Value::from("John Doe")); assert_eq!(person["age"], Value::Int(37)); assert_eq!(person["SSN"], Value::Nil); assert_eq!(person["children"][0], Value::from("Mark")); assert_eq!(person["children"][0]["age"], Value::Nil); assert_eq!(person["children"][2], Value::Nil); // extract values assert_eq!(person["name"].as_str(), Some("John Doe")); assert_eq!(person["age"].as_i32(), Some(37)); assert_eq!(person["age"].as_bool(), None); assert_eq!(person["children"].as_array().unwrap().len(), 2);
Variants
Int(i32)
<i4>
or <int>
, 32-bit signed integer.
Int64(i64)
<i8>
, 64-bit signed integer.
This is an XMLRPC extension and may not be supported by all clients / servers.
Bool(bool)
<boolean>
, 0 == false
, 1 == true
.
String(String)
<string>
Double(f64)
<double>
DateTime(DateTime)
<dateTime.iso8601>
, an ISO 8601 formatted date/time value.
Base64(Vec<u8>)
<base64>
, base64-encoded binary data.
Struct(BTreeMap<String, Value>)
<struct>
, a mapping of named values.
Array(Vec<Value>)
<array>
, a list of arbitrary (heterogeneous) values.
Nil
<nil/>
, the empty (Unit) value.
This is an XMLRPC extension and may not be supported by all clients / servers.
Methods
impl Value
[src]
fn write_as_xml<W: Write>(&self, fmt: &mut W) -> Result<()>
[src]
Formats this Value
as an XML <value>
element.
Errors
Any error reported by the writer will be propagated to the caller.
fn get<I: Index>(&self, index: I) -> Option<&Value>
[src]
Returns an inner struct or array value indexed by index
.
Returns None
if the member doesn't exist or self
is neither a struct nor an array.
You can also use Rust's square-bracket indexing syntax to perform this operation if you want
a default value instead of an Option
. Refer to the top-level examples for
details.
fn as_i32(&self) -> Option<i32>
[src]
If the Value
is a normal integer (Value::Int
), returns associated value. Returns None
otherwise.
In particular, None
is also returned if self
is a Value::Int64
. Use as_i64
to
handle this case.
fn as_i64(&self) -> Option<i64>
[src]
If the Value
is an integer, returns associated value. Returns None
otherwise.
This works with both Value::Int
and Value::Int64
.
fn as_bool(&self) -> Option<bool>
[src]
If the Value
is a boolean, returns associated value. Returns None
otherwise.
fn as_str(&self) -> Option<&str>
[src]
If the Value
is a string, returns associated value. Returns None
otherwise.
fn as_f64(&self) -> Option<f64>
[src]
If the Value
is a floating point number, returns associated value. Returns None
otherwise.
fn as_datetime(&self) -> Option<DateTime>
[src]
If the Value
is a date/time, returns associated value. Returns None
otherwise.
fn as_bytes(&self) -> Option<&[u8]>
[src]
If the Value
is base64 binary data, returns associated value. Returns None
otherwise.
fn as_struct(&self) -> Option<&BTreeMap<String, Value>>
[src]
If the Value
is a struct, returns associated map. Returns None
otherwise.
fn as_array(&self) -> Option<&[Value]>
[src]
If the Value
is an array, returns associated slice. Returns None
otherwise.
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 From<i32> for Value
[src]
impl From<i64> for Value
[src]
impl From<bool> for Value
[src]
impl From<String> for Value
[src]
impl<'a> From<&'a str> for Value
[src]
impl From<f64> for Value
[src]
impl From<DateTime> for Value
[src]
impl From<Vec<u8>> for Value
[src]
impl<I> Index<I> for Value where
I: Index,
[src]
I: Index,