pub enum JsonValue {
    String(String),
    Integer(i64),
    Float(f64),
    Boolean(bool),
    Null,
}

Variants§

§

String(String)

§

Integer(i64)

§

Float(f64)

§

Boolean(bool)

§

Null

Implementations§

source§

impl JsonValue

source

pub fn is_string(&self) -> bool

Checks if the value is the JsonValue::String discriminant.

Examples
use json_node::JsonValue;
 
let string_value = JsonValue::String("Hello World!".to_owned());
let non_string_value = JsonValue::Null;
 
assert!(string_value.is_string());
assert!(!non_string_value.is_string());
source

pub fn is_integer(&self) -> bool

Checks if the value is the JsonValue::Integer discriminant.

Examples
use json_node::JsonValue;
 
let integer_value = JsonValue::Integer(42);
let non_integer_value = JsonValue::Null;
 
assert!(integer_value.is_integer());
assert!(!non_integer_value.is_integer());
source

pub fn is_float(&self) -> bool

Checks if the value is the JsonValue::Float discriminant.

Examples
use json_node::JsonValue;
 
let float_value = JsonValue::Float(3.14);
let non_float_value = JsonValue::Null;
 
assert!(float_value.is_float());
assert!(!non_float_value.is_float());
source

pub fn is_bool(&self) -> bool

Checks if the value is the JsonValue::Boolean discriminant.

Examples
use json_node::JsonValue;
 
let bool_value = JsonValue::Boolean(true);
let non_bool_value = JsonValue::Null;
 
assert!(bool_value.is_bool());
assert!(!non_bool_value.is_bool());
source

pub fn is_null(&self) -> bool

Checks if the value is the JsonValue::Null discriminant.

Examples
use json_node::JsonValue;
 
let null_value = JsonValue::Null;
let non_null_value = JsonValue::Integer(42);
 
assert!(null_value.is_null());
assert!(!non_null_value.is_null());
source

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

Extracts the inner str contained inside the node if it is the JsonValue::String discriminant.

Examples
use json_node::JsonValue;
 
let string_value = JsonValue::String("Hello World!".to_owned());
let non_string_value = JsonValue::Null;
 
assert_eq!(string_value.as_string(), Some("Hello World!"));
assert_eq!(non_string_value.as_string(), None);
source

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

Extracts the inner i64 contained inside the node if it is the JsonValue::Integer discriminant.

Examples
use json_node::JsonValue;
 
let integer_value = JsonValue::Integer(42);
let non_integer_value = JsonValue::Null;
 
assert_eq!(integer_value.as_integer(), Some(&42));
assert_eq!(non_integer_value.as_integer(), None);
source

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

Extracts the inner f64 contained inside the node if it is the JsonValue::Float discriminant.

Examples
use json_node::JsonValue;
 
let float_value = JsonValue::Float(3.14);
let non_float_value = JsonValue::Null;
 
assert_eq!(float_value.as_float(), Some(&3.14));
assert_eq!(non_float_value.as_float(), None);
source

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

Extracts the inner bool contained inside the node if it is the JsonValue::Boolean discriminant.

Examples
use json_node::JsonValue;
 
let bool_value = JsonValue::Boolean(true);
let non_bool_value = JsonValue::Null;
 
assert_eq!(bool_value.as_boolean(), Some(&true));
assert_eq!(non_bool_value.as_boolean(), None);
source

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

Extracts the inner mut str contained inside the node if it is the JsonValue::String discriminant.

Examples
use json_node::JsonValue;
 
let mut string_value = JsonValue::String("Hello World!".to_owned());
let mut non_string_value = JsonValue::Null;
 
assert_eq!(string_value.as_string_mut(), Some("Hello World!".to_string().as_mut_str()));
assert_eq!(non_string_value.as_string_mut(), None);
source

pub fn as_integer_mut(&mut self) -> Option<&mut i64>

Extracts the inner mut i64 contained inside the node if it is the JsonValue::Integer discriminant.

Examples
use json_node::JsonValue;
 
let mut integer_value = JsonValue::Integer(42);
let mut non_integer_value = JsonValue::Null;
 
assert_eq!(integer_value.as_integer_mut(), Some(&mut 42));
assert_eq!(non_integer_value.as_integer_mut(), None);
source

pub fn as_float_mut(&mut self) -> Option<&mut f64>

Extracts the inner mut f64 contained inside the node if it is the JsonValue::Float discriminant.

Examples
use json_node::JsonValue;
 
let mut float_value = JsonValue::Float(3.14);
let mut non_float_value = JsonValue::Null;
 
assert_eq!(float_value.as_float_mut(), Some(&mut 3.14));
assert_eq!(non_float_value.as_float_mut(), None);
source

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

Extracts the inner mut bool contained inside the node if it is the JsonValue::Boolean discriminant.

Examples
use json_node::JsonValue;
 
let mut bool_value = JsonValue::Boolean(true);
let mut non_bool_value = JsonValue::Null;
 
assert_eq!(bool_value.as_boolean_mut(), Some(&mut true));
assert_eq!(non_bool_value.as_boolean_mut(), None);
source

pub fn to_json_string(&self) -> String

Converts the JsonValue into a JSON representation of the value.

Examples
use json_node::JsonValue;
 
let string_value = JsonValue::String("Hello World!".to_owned());
 
assert_eq!(string_value.to_json_string(), "\"Hello World!\"");

Trait Implementations§

source§

impl Clone for JsonValue

source§

fn clone(&self) -> JsonValue

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 JsonValue

source§

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

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

impl Display for JsonValue

source§

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

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

impl PartialEq<JsonValue> for JsonValue

source§

fn eq(&self, other: &JsonValue) -> 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 JsonValue

Auto Trait Implementations§

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 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.
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.
source§

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

Performs the conversion.