Enum valu3::value::Value

source ·
pub enum Value {
    String(StringB),
    Number(Number),
    Boolean(bool),
    Array(Array),
    Object(Object),
    Null,
    Undefined,
    DateTime(DateTime),
}
Expand description

Represents different data types as an enum.

Variants§

§

String(StringB)

§

Number(Number)

§

Boolean(bool)

§

Array(Array)

§

Object(Object)

§

Null

§

Undefined

§

DateTime(DateTime)

Implementations§

source§

impl Value

source

pub fn to_json(&self, mode: JsonMode) -> String

Converts a Value into a JSON string.

§Arguments
  • mode - A JsonMode value representing the JSON output format mode.
§Examples
use json_utils::{Value, JsonMode};

let value = Value::payload_to_value("{\"name\":\"John Doe\",\"age\":30,\"is_active\":true}").unwrap();
let json_string = value.to_json(JsonMode::Indented);
println!("{}", json_string);
source§

impl Value

source

pub fn to_yaml_with_indent(&self, indent: usize) -> String

Returns the YAML representation of the given Value with the specified indentation.

§Arguments
  • indent - The number of spaces to use for indentation.
§Example
let value = Value::from(vec![Value::from(1), Value::from(2), Value::from(3)]);
assert_eq!(value.to_yaml_with_indent(2), " - 1\n   - 2\n   - 3\n".to_string());
source

pub fn to_yaml(&self) -> String

Returns the YAML representation of the given Value.

§Example
let value = Value::from(vec![Value::from(1), Value::from(2), Value::from(3)]);
assert_eq!(value.to_yaml(), "- 1\n  - 2\n  - 3\n".to_string());
source§

impl Value

source

pub fn get<T>(&self, key: T) -> Option<&Value>

source

pub fn get_mut<T>(&mut self, key: T) -> Option<&mut Value>

source

pub fn clean(&mut self)

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn is_string(&self) -> bool

source

pub fn is_number(&self) -> bool

source

pub fn is_array(&self) -> bool

source

pub fn is_object(&self) -> bool

source

pub fn is_bool(&self) -> bool

source

pub fn is_null(&self) -> bool

source

pub fn is_undefined(&self) -> bool

source

pub fn as_string_b(&self) -> Option<&StringB>

source

pub fn as_number(&self) -> Option<&Number>

source

pub fn as_array(&self) -> Option<&Array>

source

pub fn as_object(&self) -> Option<&Object>

source

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

source

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

source

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

source

pub fn as_string_mut(&mut self) -> Option<&mut StringB>

source

pub fn as_number_mut(&mut self) -> Option<&mut Number>

source

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

source

pub fn as_object_mut(&mut self) -> Option<&mut Object>

source

pub fn as_bool_mut(&mut self) -> Option<&mut bool>

source

pub fn as_null_mut(&mut self) -> Option<()>

source

pub fn as_undefined_mut(&mut self) -> Option<()>

source

pub fn push<T: ToValueBehavior>(&mut self, value: T)

source

pub fn insert<T, V>(&mut self, key: T, value: V) -> Option<Value>

source§

impl Value

Trait Implementations§

source§

impl ArrayBehavior for Value

source§

fn pop(&mut self) -> Option<Value>

Removes the last element from the array and returns it, or None if the array is empty. Read more
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 DateTimeBehavior for Value

source§

fn as_date(&self) -> Option<&NaiveDate>

source§

fn as_time(&self) -> Option<&NaiveTime>

source§

fn as_date_time(&self) -> Option<&DateTime<Utc>>

source§

fn year(&self) -> Option<i32>

source§

fn month(&self) -> Option<u32>

source§

fn day(&self) -> Option<u32>

source§

fn hour(&self) -> Option<u32>

source§

fn minute(&self) -> Option<u32>

source§

fn second(&self) -> Option<u32>

source§

fn timestamp(&self) -> Option<i64>

source§

fn timezone(&self) -> Option<Utc>

source§

fn to_iso8601(&self) -> String

source§

fn to_rfc3339(&self) -> String

source§

fn add_duration(&self, duration: Duration) -> Option<Self>
where Self: Sized,

source§

fn subtract_duration(&self, duration: Duration) -> Option<Self>
where Self: Sized,

source§

fn duration_between(&self, other: &Self) -> Option<Duration>

source§

fn from_ymd_opt(year: i32, month: u32, day: u32) -> Self

source§

fn with_ymd_and_hms( year: i32, month: u32, day: u32, hour: u32, min: u32, sec: u32, ) -> Self

source§

fn now() -> Self

source§

impl Debug for Value

source§

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

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

impl Default for Value

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Value

source§

fn deserialize<D>(deserializer: D) -> Result<Value, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Value

source§

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

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

impl From<()> for Value

source§

fn from(_: ()) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Value

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl From<Value> for Array

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for DateTime

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl<K, V> From<Vec<(K, V)>> for Value

source§

fn from(value: Vec<(K, V)>) -> Self

Converts to this type from the input type.
source§

impl<K> From<Vec<(K, Value)>> for Value

source§

fn from(value: Vec<(K, Value)>) -> Self

Converts to this type from the input type.
source§

impl FromValueBehavior for Value

§

type Item = Value

source§

fn from_value(value: Value) -> Option<Self::Item>

Converts a Value into a type.
source§

impl NumberBehavior for Value

source§

fn set_u8(&mut self, value: u8)

Sets the value of the Number struct to the given u8 value. Read more
source§

fn set_u16(&mut self, value: u16)

source§

fn set_u32(&mut self, value: u32)

source§

fn set_u64(&mut self, value: u64)

source§

fn set_u128(&mut self, value: u128)

source§

fn set_i8(&mut self, value: i8)

source§

fn set_i16(&mut self, value: i16)

source§

fn set_i32(&mut self, value: i32)

source§

fn set_i64(&mut self, value: i64)

source§

fn set_i128(&mut self, value: i128)

source§

fn set_f32(&mut self, value: f32)

source§

fn set_f64(&mut self, value: f64)

source§

fn get_u8(&self) -> Option<u8>

Returns the u8 value stored in the Number struct, if any. Read more
source§

fn get_u16(&self) -> Option<u16>

source§

fn get_u32(&self) -> Option<u32>

source§

fn get_u64(&self) -> Option<u64>

source§

fn get_u128(&self) -> Option<u128>

source§

fn get_i8(&self) -> Option<i8>

source§

fn get_i16(&self) -> Option<i16>

source§

fn get_i32(&self) -> Option<i32>

source§

fn get_i64(&self) -> Option<i64>

source§

fn get_i128(&self) -> Option<i128>

source§

fn get_f32(&self) -> Option<f32>

source§

fn get_f64(&self) -> Option<f64>

source§

fn get_u8_unsafe(&self) -> u8

Returns the u8 value stored in the Number struct, without checking if it exists. Read more
source§

fn get_u16_unsafe(&self) -> u16

source§

fn get_u32_unsafe(&self) -> u32

source§

fn get_u64_unsafe(&self) -> u64

source§

fn get_u128_unsafe(&self) -> u128

source§

fn get_i8_unsafe(&self) -> i8

source§

fn get_i16_unsafe(&self) -> i16

source§

fn get_i32_unsafe(&self) -> i32

source§

fn get_i64_unsafe(&self) -> i64

source§

fn get_i128_unsafe(&self) -> i128

source§

fn get_f32_unsafe(&self) -> f32

source§

fn get_f64_unsafe(&self) -> f64

source§

fn is_i8(&self) -> bool

Checks if the stored number is of type i8. Read more
source§

fn is_i16(&self) -> bool

source§

fn is_i32(&self) -> bool

source§

fn is_i64(&self) -> bool

source§

fn is_i128(&self) -> bool

source§

fn is_u8(&self) -> bool

source§

fn is_u16(&self) -> bool

source§

fn is_u32(&self) -> bool

source§

fn is_u64(&self) -> bool

source§

fn is_u128(&self) -> bool

source§

fn is_f32(&self) -> bool

source§

fn is_f64(&self) -> bool

source§

fn is_number(&self) -> bool

Checks if the Number struct contains any value. Read more
source§

fn is_integer(&self) -> bool

source§

fn is_float(&self) -> bool

source§

fn is_signed(&self) -> bool

source§

fn is_unsigned(&self) -> bool

source§

fn is_zero(&self) -> bool

source§

fn is_positive(&self) -> bool

source§

fn is_negative(&self) -> bool

source§

fn number_type(&self) -> NumberType

fn is_integer(&self) -> bool { /* … */ } Determines the type of number stored in the Number struct. Read more
source§

impl ObjectBehavior for Value

source§

fn remove<T>(&mut self, key: &T) -> Option<Value>

Removes a key-value pair from the object and returns the associated value. If the key is not present, returns None.
source§

fn contains_key<T>(&self, key: &T) -> bool

Returns true if the object contains a value for the specified key, otherwise false.
source§

fn keys(&self) -> Vec<&ValueKey>

Returns a Vec of references to the keys in the object, in the order they were inserted.
source§

fn values(&self) -> Vec<&Value>

Returns a Vec of references to the values in the object, in the order they were inserted.
source§

impl PartialEq for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Value

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StringBehavior for Value

source§

fn as_bytes(&self) -> &[u8]

Gets the byte representation of the string. Read more
source§

fn as_str(&self) -> &str

Gets the string slice representation of the value. Read more
source§

fn as_string(&self) -> String

Converts the value to a String. Read more
source§

fn extract(&self) -> String

source§

fn to_uppercase(&self) -> Self

Converts the string to uppercase. Read more
source§

fn to_lowercase(&self) -> Self

Converts the string to lowercase. Read more
source§

fn trim(&self) -> Self

Removes whitespace at the beginning and end of the string. Read more
source§

fn replace(&self, from: &str, to: &str) -> Self

Replaces all occurrences of ‘from’ with ‘to’. Read more
source§

fn concat<T: AsRef<str>>(&self, other: T) -> Self

Concatenates the current string with another string or &str. Read more
source§

fn from_utf8(value: Vec<u8>) -> Self

source§

impl ToValueBehavior for Value

source§

fn to_value(&self) -> Value

Converts a type into a Value.
source§

impl StructuralPartialEq for Value

source§

impl ValueTrait 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§

default 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> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,