pub enum Value {
Null,
Boolean(bool),
Number(Number),
String(String),
Array(Vec<Value>),
Object(ValueMap),
}
Expand description
JSON Value.
Variants§
Null
Null value.
null
Boolean(bool)
A boolean value.
true
or
false
Number(Number)
String(String)
A UTF-8 encoded string.
"The quick brown fox jumps over the lazy dog.\nhello, world"
The following characters must be escaped:
\u{0}
to\u{1f}
(inclusive)\n
(newline)\r
(carriage return)\t
(tab) (optional)"
'
(optional)\
/
(optional)\u{8}
\u{c}
Array(Vec<Value>)
An array of JSON Values.
[
"hello, world",
1234,
3.14,
true,
false,
null,
]
Object(ValueMap)
A Mapping of JSON Values by their name.
{
"tag": null,
"registered": true,
"age": 197,
"name": "Fred",
"classes": [
"Algebra",
"History of Programming",
"Algorithms and Datastructures",
"Cryptography",
],
"rgb_for_some_reason": {
"r": 4,
"g": 7
"b": 3,
}
}
Implementations§
Source§impl Value
impl Value
Sourcepub fn pretty_print_format(
&self,
indent: Indent,
spacing: bool,
) -> PrettyPrint<'_>
pub fn pretty_print_format( &self, indent: Indent, spacing: bool, ) -> PrettyPrint<'_>
Returns an object suitable for pretty printing.
§Arguments:
indent
: Controls the indentation. UseIndent::Spaces(0)
if you don’t want indentation (This defeats the purpose of pretty printing).spacing
: Determines whether or not there are spaces before and after colons.
Sourcepub fn pretty_print(&self) -> PrettyPrint<'_>
pub fn pretty_print(&self) -> PrettyPrint<'_>
Returns the default pretty printer.
Source§impl Value
impl Value
Sourcepub fn push<T: Into<Value>>(&mut self, value: T)
pub fn push<T: Into<Value>>(&mut self, value: T)
Push value
into a Value::Array. If the Value is Value::Null, convert it
into a Value::Array and push value
into it.
Panics if self Value is not Value::Null or Value::Array.
Sourcepub fn insert<T: Into<Value>, K: InsertKey>(
&mut self,
k: K,
v: T,
) -> Option<Value>
pub fn insert<T: Into<Value>, K: InsertKey>( &mut self, k: K, v: T, ) -> Option<Value>
Insert value
into a Value::Object. If the Value is Value::Null, convert it
into a Value::Array and insert value
into it.
Panics if self Value is not Value::Null or Value::Array.
Sourcepub fn get<I: IndexOrKey>(&self, i_k: I) -> Option<&Value>
pub fn get<I: IndexOrKey>(&self, i_k: I) -> Option<&Value>
Get an immutable reference to a Value by index or key.
Sourcepub fn get_mut<I: IndexOrKey>(&mut self, i_k: I) -> Option<&mut Value>
pub fn get_mut<I: IndexOrKey>(&mut self, i_k: I) -> Option<&mut Value>
Get a mutable reference to a Value by index or key.
Trait Implementations§
Source§impl<I: IndexOrKey> Index<I> for Value
impl<I: IndexOrKey> Index<I> 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