Enum Value

Source
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,
}
Expand description

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)

A 32-bit signed integer (<i4> or <int>).

§

Int64(i64)

A 64-bit signed integer (<i8>).

This is an XMLRPC extension and may not be supported by all clients / servers.

§

Bool(bool)

A boolean value (<boolean>, 0 == false, 1 == true).

§

String(String)

A string (<string>).

§

Double(f64)

A double-precision IEEE 754 floating point number (<double>).

§

DateTime(DateTime)

An ISO 8601 formatted date/time value (<dateTime.iso8601>).

Note that ISO 8601 is highly ambiguous and allows incomplete date-time specifications. For example, servers will frequently leave out timezone information, in which case the client must know which timezone is used by the server. For this reason, the contained DateTime struct only contains the raw fields specified by the server, without any real date/time functionality like what’s offered by the chrono crate.

To make matters worse, some clients don’t seem to support time zone information in datetime values. To ensure compatiblity, the xmlrpc crate will try to format datetime values like the example given in the specification if the timezone offset is zero.

Recommendation: Avoid DateTime if possible. A date and time can be specified more precisely by formatting it using RFC 3339 and putting it in a String.

§

Base64(Vec<u8>)

Base64-encoded binary data (<base64>).

§

Struct(BTreeMap<String, Value>)

A mapping of named values (<struct>).

§

Array(Vec<Value>)

A list of arbitrary (heterogeneous) values (<array>).

§

Nil

The empty (Unit) value (<nil/>).

This is an XMLRPC extension and may not be supported by all clients / servers.

Implementations§

Source§

impl Value

Source

pub fn write_as_xml<W: Write>(&self, fmt: &mut W) -> Result<()>

Formats this Value as an XML <value> element.

§Errors

Any error reported by the writer will be propagated to the caller.

Source

pub fn get<I: Index>(&self, index: I) -> Option<&Value>

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.

Source

pub fn as_i32(&self) -> Option<i32>

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.

Source

pub fn as_i64(&self) -> Option<i64>

If the Value is an integer, returns associated value. Returns None otherwise.

This works with both Value::Int and Value::Int64.

Source

pub fn as_bool(&self) -> Option<bool>

If the Value is a boolean, returns associated value. Returns None otherwise.

Source

pub fn as_str(&self) -> Option<&str>

If the Value is a string, returns associated value. Returns None otherwise.

Source

pub fn as_f64(&self) -> Option<f64>

If the Value is a floating point number, returns associated value. Returns None otherwise.

Source

pub fn as_datetime(&self) -> Option<DateTime>

If the Value is a date/time, returns associated value. Returns None otherwise.

Source

pub fn as_bytes(&self) -> Option<&[u8]>

If the Value is base64 binary data, returns associated value. Returns None otherwise.

Source

pub fn as_struct(&self) -> Option<&BTreeMap<String, Value>>

If the Value is a struct, returns associated map. Returns None otherwise.

Source

pub fn as_array(&self) -> Option<&[Value]>

If the Value is an array, returns associated slice. Returns None otherwise.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a str> for Value

Source§

fn from(other: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime> for Value

Source§

fn from(other: DateTime) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Option<&'a str>> for Value

Source§

fn from(other: Option<&'a str>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<DateTime>> for Value

Source§

fn from(other: Option<DateTime>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<String>> for Value

Source§

fn from(other: Option<String>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<Vec<u8>>> for Value

Source§

fn from(other: Option<Vec<u8>>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<bool>> for Value

Source§

fn from(other: Option<bool>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<f64>> for Value

Source§

fn from(other: Option<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<i32>> for Value

Source§

fn from(other: Option<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<i64>> for Value

Source§

fn from(other: Option<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(other: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(other: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(other: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(other: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(other: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(other: i64) -> Self

Converts to this type from the input type.
Source§

impl<I> Index<I> for Value
where I: Index,

Source§

type Output = Value

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more