rocket_config

Enum Value

Source
pub enum Value {
    Null,
    Bool(bool),
    Number(Number),
    String(String),
    Array(Vec<Value>),
    Object(BTreeMap<String, Value>),
}
Expand description

The Value enum, a loosely typed way of representing any valid value.

It is used to contains the parsing result of serde_json or serde_yaml.

Variants§

§

Null

Represents a null value.

§

Bool(bool)

Represents a boolean.

§

Number(Number)

Represents a number, whether integer or floating point.

§

String(String)

Represents a string.

§

Array(Vec<Value>)

Represents an array.

§

Object(BTreeMap<String, Value>)

Represents an object.

Implementations§

Source§

impl Value

Source

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

Index into an array or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of an array.

Returns None if the type of self does not match the type of the index, for example if the index is a string and self is an array or a number. Also returns None if the given key does not exist in the map or the given index is not within the bounds of the array.

Source

pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Self>

Index into a JSON array or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of an array.

Returns None if the type of self does not match the type of the index, for example if the index is a string and self is an array or a number. Also returns None if the given key does not exist in the map or the given index is not within the bounds of the array.

Source

pub fn is_object(&self) -> bool

Returns true if the Value is an Object. Returns false otherwise.

For any Value on which is_object returns true, as_object and as_object_mut are guaranteed to return the map representation of the object.

Source

pub fn as_object(&self) -> Option<&BTreeMap<String, Self>>

If the Value is an Object, returns the associated Map. Returns None otherwise.

Source

pub fn as_object_mut(&mut self) -> Option<&mut BTreeMap<String, Self>>

If the Value is an Object, returns the associated mutable Map. Returns None otherwise.

Source

pub fn is_array(&self) -> bool

Returns true if the Value is an Array. Returns false otherwise.

For any Value on which is_array returns true, as_array and as_array_mut are guaranteed to return the vector representing the array.

Source

pub fn as_array(&self) -> Option<&Vec<Self>>

If the Value is an Array, returns the associated vector. Returns None otherwise.

Source

pub fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>

If the Value is an Array, returns the associated mutable vector. Returns None otherwise.

Source

pub fn is_string(&self) -> bool

Returns true if the Value is a String. Returns false otherwise.

For any Value on which is_string returns true, as_str is guaranteed to return the string slice.

Source

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

If the Value is a String, returns the associated str. Returns None otherwise.

Source

pub fn is_number(&self) -> bool

Returns true if the Value is a Number. Returns false otherwise.

Source

pub fn is_i64(&self) -> bool

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.

Source

pub fn is_u64(&self) -> bool

Returns true if the Value is an integer between zero and u64::MAX.

For any Value on which is_u64 returns true, as_u64 is guaranteed to return the integer value.

Source

pub fn is_f64(&self) -> bool

Returns true if the Value is a number that can be represented by 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 but this is not a guarantee in the future.

Source

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

If the Value is an integer, represent it as i64 if possible. Returns None otherwise.

Source

pub fn as_u64(&self) -> Option<u64>

If the Value is an integer, represent it as u64 if possible. Returns None otherwise.

Source

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

If the Value is a number, represent it as f64 if possible. Returns None otherwise.

Source

pub fn is_boolean(&self) -> bool

Returns true if the Value is a Boolean. Returns false otherwise.

For any Value on which is_boolean returns true, as_bool is guaranteed to return the boolean value.

Source

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

If the Value is a Boolean, returns the associated bool. Returns None otherwise.

Source

pub fn is_null(&self) -> bool

Returns true if the Value is a Null. Returns false otherwise.

For any Value on which is_null returns true, as_null is guaranteed to return Some(()).

Source

pub fn as_null(&self) -> Option<()>

If the Value is a Null, returns (). Returns None otherwise.

Source

pub fn take(&mut self) -> Self

Takes the value out of the Value, leaving a Null in its place.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a copy 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, formatter: &mut Formatter<'_>) -> Result

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

impl Default for Value

The default value is Value::Null.

This is useful for handling omitted Value fields when deserializing.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&Value> for Value

Source§

fn from(json: &Value) -> Self

Converts serde_json deserialization results under a common value: Value.

serde_yaml Value

Source§

impl From<&Value> for Value

Source§

fn from(yaml: &Value) -> Self

Converts serde_yaml deserialization results under a common value: Value.

serde_yaml Value

Source§

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

Source§

fn index(&self, index: I) -> &Value

Index into a rocket_config::Value using the syntax value[0] or value["k"].

Returns Value::Null if the type of self does not match the type of the index, for example if the index is a string and self is an array or a number. Also returns Value::Null if the given key does not exist in the map or the given index is not within the bounds of the array.

For retrieving deeply nested values, you should have a look at the Value::pointer method.

Source§

type Output = Value

The returned type after indexing.
Source§

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

Source§

fn index_mut(&mut self, index: I) -> &mut Value

Write into a rocket_config::Value using the syntax value[0] = ... or value["k"] = ....

If the index is a number, the value must be an array of length bigger than the index. Indexing into a value that is not an array or an array that is too small will panic.

If the index is a string, the value must be an object or null which is treated like an empty object. If the key is not already present in the object, it will be inserted with a value of null. Indexing into a value that is neither an object nor null will panic.

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 PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Value) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
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, I> AsResult<T, I> for T
where I: Input,

Source§

fn as_result(self) -> Result<T, ParseErr<I>>

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, dst: *mut T)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoCollection<T> for T

Source§

fn into_collection<A>(self) -> SmallVec<A>
where A: Array<Item = T>,

Converts self into a collection.
Source§

fn mapped<U, F, A>(self, f: F) -> SmallVec<A>
where F: FnMut(T) -> U, A: Array<Item = U>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V