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
impl Value
sourcepub fn to_json(&self, mode: JsonMode) -> String
pub fn to_json(&self, mode: JsonMode) -> String
Converts a Value
into a JSON string.
§Arguments
mode
- AJsonMode
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
impl Value
sourcepub fn to_yaml_with_indent(&self, indent: usize) -> String
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§impl Value
impl Value
pub fn get<T>(&self, key: T) -> Option<&Value>where
T: ValueKeyBehavior,
pub fn get_mut<T>(&mut self, key: T) -> Option<&mut Value>where
T: ValueKeyBehavior,
pub fn clean(&mut self)
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_object(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_null(&self) -> bool
pub fn is_undefined(&self) -> bool
pub fn as_string_b(&self) -> Option<&StringB>
pub fn as_number(&self) -> Option<&Number>
pub fn as_array(&self) -> Option<&Array>
pub fn as_object(&self) -> Option<&Object>
pub fn as_bool(&self) -> Option<&bool>
pub fn as_null(&self) -> Option<()>
pub fn as_undefined(&self) -> Option<()>
pub fn as_string_mut(&mut self) -> Option<&mut StringB>
pub fn as_number_mut(&mut self) -> Option<&mut Number>
pub fn as_array_mut(&mut self) -> Option<&mut Array>
pub fn as_object_mut(&mut self) -> Option<&mut Object>
pub fn as_bool_mut(&mut self) -> Option<&mut bool>
pub fn as_null_mut(&mut self) -> Option<()>
pub fn as_undefined_mut(&mut self) -> Option<()>
pub fn push<T: ToValueBehavior>(&mut self, value: T)
pub fn insert<T, V>(&mut self, key: T, value: V) -> Option<Value>where
T: ValueKeyBehavior,
V: ToValueBehavior,
Trait Implementations§
source§impl ArrayBehavior for Value
impl ArrayBehavior for Value
source§impl DateTimeBehavior for Value
impl DateTimeBehavior for Value
fn as_date(&self) -> Option<&NaiveDate>
fn as_time(&self) -> Option<&NaiveTime>
fn as_date_time(&self) -> Option<&DateTime<Utc>>
fn year(&self) -> Option<i32>
fn month(&self) -> Option<u32>
fn day(&self) -> Option<u32>
fn hour(&self) -> Option<u32>
fn minute(&self) -> Option<u32>
fn second(&self) -> Option<u32>
fn timestamp(&self) -> Option<i64>
fn timezone(&self) -> Option<Utc>
fn to_iso8601(&self) -> String
fn to_rfc3339(&self) -> String
fn add_duration(&self, duration: Duration) -> Option<Self>where
Self: Sized,
fn subtract_duration(&self, duration: Duration) -> Option<Self>where
Self: Sized,
fn duration_between(&self, other: &Self) -> Option<Duration>
fn from_ymd_opt(year: i32, month: u32, day: u32) -> Self
fn with_ymd_and_hms( year: i32, month: u32, day: u32, hour: u32, min: u32, sec: u32, ) -> Self
fn now() -> Self
source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
source§fn deserialize<D>(deserializer: D) -> Result<Value, D::Error>where
D: Deserializer<'de>,
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<T> From<T> for Valuewhere
T: ToValueBehavior + PrimitiveType,
impl<T> From<T> for Valuewhere
T: ToValueBehavior + PrimitiveType,
source§impl FromValueBehavior for Value
impl FromValueBehavior for Value
source§impl NumberBehavior for Value
impl NumberBehavior for Value
fn set_u16(&mut self, value: u16)
fn set_u32(&mut self, value: u32)
fn set_u64(&mut self, value: u64)
fn set_u128(&mut self, value: u128)
fn set_i8(&mut self, value: i8)
fn set_i16(&mut self, value: i16)
fn set_i32(&mut self, value: i32)
fn set_i64(&mut self, value: i64)
fn set_i128(&mut self, value: i128)
fn set_f32(&mut self, value: f32)
fn set_f64(&mut self, value: f64)
fn get_u16(&self) -> Option<u16>
fn get_u32(&self) -> Option<u32>
fn get_u64(&self) -> Option<u64>
fn get_u128(&self) -> Option<u128>
fn get_i8(&self) -> Option<i8>
fn get_i16(&self) -> Option<i16>
fn get_i32(&self) -> Option<i32>
fn get_i64(&self) -> Option<i64>
fn get_i128(&self) -> Option<i128>
fn get_f32(&self) -> Option<f32>
fn get_f64(&self) -> Option<f64>
source§fn get_u8_unsafe(&self) -> u8
fn get_u8_unsafe(&self) -> u8
fn get_u16_unsafe(&self) -> u16
fn get_u32_unsafe(&self) -> u32
fn get_u64_unsafe(&self) -> u64
fn get_u128_unsafe(&self) -> u128
fn get_i8_unsafe(&self) -> i8
fn get_i16_unsafe(&self) -> i16
fn get_i32_unsafe(&self) -> i32
fn get_i64_unsafe(&self) -> i64
fn get_i128_unsafe(&self) -> i128
fn get_f32_unsafe(&self) -> f32
fn get_f64_unsafe(&self) -> f64
fn is_i16(&self) -> bool
fn is_i32(&self) -> bool
fn is_i64(&self) -> bool
fn is_i128(&self) -> bool
fn is_u8(&self) -> bool
fn is_u16(&self) -> bool
fn is_u32(&self) -> bool
fn is_u64(&self) -> bool
fn is_u128(&self) -> bool
fn is_f32(&self) -> bool
fn is_f64(&self) -> bool
fn is_integer(&self) -> bool
fn is_float(&self) -> bool
fn is_signed(&self) -> bool
fn is_unsigned(&self) -> bool
fn is_zero(&self) -> bool
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
source§fn number_type(&self) -> NumberType
fn number_type(&self) -> NumberType
fn is_integer(&self) -> bool { /* … */ }
Determines the type of number stored in the
Number
struct. Read moresource§impl ObjectBehavior for Value
impl ObjectBehavior for Value
source§fn remove<T>(&mut self, key: &T) -> Option<Value>where
T: ValueKeyBehavior,
fn remove<T>(&mut self, key: &T) -> Option<Value>where
T: ValueKeyBehavior,
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) -> boolwhere
T: ValueKeyBehavior,
fn contains_key<T>(&self, key: &T) -> boolwhere
T: ValueKeyBehavior,
Returns
true
if the object contains a value for the specified key, otherwise false
.source§impl PartialEq for Value
impl PartialEq for Value
source§impl PartialOrd for Value
impl PartialOrd for Value
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl StringBehavior for Value
impl StringBehavior for Value
fn extract(&self) -> String
source§fn to_uppercase(&self) -> Self
fn to_uppercase(&self) -> Self
Converts the string to uppercase. Read more
source§fn to_lowercase(&self) -> Self
fn to_lowercase(&self) -> Self
Converts the string to lowercase. Read more
source§fn replace(&self, from: &str, to: &str) -> Self
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
fn concat<T: AsRef<str>>(&self, other: T) -> Self
Concatenates the current string with another string or
&str
. Read morefn from_utf8(value: Vec<u8>) -> Self
source§impl ToValueBehavior for Value
impl ToValueBehavior for Value
impl StructuralPartialEq for Value
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)