Enum purp_value::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::str_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 str_to_value(str: &str) -> Result<Value, Error>

Parses a string to a Value.

Arguments
  • str - A string slice to parse.
Errors

Returns an Error if the string is not parseable.

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, 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 Display for Value

source§

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

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

impl From<&str> for Value

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl From<()> for Value

source§

fn from(_: ()) -> Self

Converts to this type from the input type.
source§

impl From<BTreeMap<String, Value, Global>> for Value

source§

fn from(value: BTreeMap<String, Value>) -> Self

Converts to this type from the input type.
source§

impl From<HashMap<String, Value, RandomState>> for Value

source§

fn from(value: HashMap<String, Value>) -> Self

Converts to this type from the input type.
source§

impl From<Number> for Value

source§

fn from(value: Number) -> Self

Converts to this type from the input type.
source§

impl From<Option<BTreeMap<String, Value, Global>>> for Value

source§

fn from(value: Option<BTreeMap<String, Value>>) -> Self

Converts to this type from the input type.
source§

impl From<Option<HashMap<String, Value, RandomState>>> for Value

source§

fn from(value: Option<HashMap<String, Value>>) -> Self

Converts to this type from the input type.
source§

impl From<Option<String>> for Value

source§

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

Converts to this type from the input type.
source§

impl<T> From<Option<T>> for Valuewhere T: Into<Number>,

source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
source§

impl From<Option<Vec<Value, Global>>> for Value

source§

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

Converts to this type from the input type.
source§

impl From<String> for Value

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl From<StringB> for Value

source§

fn from(value: StringB) -> 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<Vec<Value, Global>> for Value

source§

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

Converts to this type from the input type.
source§

impl From<bool> for Value

source§

fn from(value: bool) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Value

source§

fn from(value: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Value

source§

fn from(value: f64) -> Self

Converts to this type from the input type.
source§

impl From<i128> for Value

source§

fn from(value: i128) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Value

source§

fn from(value: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Value

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Value

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl From<i8> for Value

source§

fn from(value: i8) -> Self

Converts to this type from the input type.
source§

impl From<u128> for Value

source§

fn from(value: u128) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Value

source§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Value

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Value

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Value

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Value> 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 StructuralPartialEq for Value

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.