Enum json_syntax::Value
source · [−]pub enum Value<M> {
Null,
Boolean(bool),
Number(NumberBuf),
String(String),
Array(Array<M>),
Object(Object<M>),
}
Expand description
Value.
The two types parameters are used to locate/map values inside the source
file.
The S
parameter is the type used to identify the source file (generally
a string slice, a path, or an index).
The P
parameter is the type used to locate the value inside the file.
By default the locspan::Span
type is used, since it is what the parser
uses.
Comparison
This type implements the usual comparison traits PartialEq
, Eq
,
PartialOrd
and Ord
. However these implementations will also compare the
code mapping information (source file and span).
If you want to do comparisons while ignoring this information, you can use
the locspan::Stripped
type.
Variants
Null
null
.
Boolean(bool)
Boolean true
or false
.
Number(NumberBuf)
Number.
String(String)
String.
Array(Array<M>)
Array.
Object(Object<M>)
Object.
Implementations
sourceimpl<M> Value<M>
impl<M> Value<M>
pub fn kind(&self) -> Kind
pub fn is_kind(&self, kind: Kind) -> bool
pub fn is_null(&self) -> bool
pub fn is_boolean(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_object(&self) -> bool
pub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean_mut(&mut self) -> Option<&mut bool>
pub fn as_number(&self) -> Option<&Number>
pub fn as_number_mut(&mut self) -> Option<&mut NumberBuf>
pub fn as_string(&self) -> Option<&str>
pub fn as_string_mut(&mut self) -> Option<&mut String>
pub fn as_array(&self) -> Option<&[Meta<Self, M>]>
pub fn as_array_mut(&mut self) -> Option<&mut Array<M>>
pub fn as_object(&self) -> Option<&Object<M>>
pub fn as_object_mut(&mut self) -> Option<&mut Object<M>>
pub fn into_boolean(self) -> Option<bool>
pub fn into_number(self) -> Option<NumberBuf>
pub fn into_string(self) -> Option<String>
pub fn into_array(self) -> Option<Array<M>>
pub fn into_object(self) -> Option<Object<M>>
sourcepub fn count(&self, f: impl Clone + Fn(&Self) -> bool) -> usize
pub fn count(&self, f: impl Clone + Fn(&Self) -> bool) -> usize
Recursively count the number of values for which f
returns true
.
sourcepub fn volume(&self) -> usize
pub fn volume(&self) -> usize
Returns the volume of the value.
The volume is the sum of all values and recursively nested values
included in self
, including self
(the volume is at least 1
).
This is equivalent to value.count(|_| true)
.
sourcepub fn map_metadata<N>(self, f: impl FnMut(M) -> N) -> Value<N>
pub fn map_metadata<N>(self, f: impl FnMut(M) -> N) -> Value<N>
Recursively maps the metadata inside the value.
Trait Implementations
sourceimpl<M, N> MapMetadataRecursively<M, N> for Value<M>
impl<M, N> MapMetadataRecursively<M, N> for Value<M>
sourceimpl<M: Ord> Ord for Value<M>
impl<M: Ord> Ord for Value<M>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<F: Clone> Parse<F> for Value<Location<F>>
impl<F: Clone> Parse<F> for Value<Location<F>>
fn parse_in<E, C>(
parser: &mut Parser<F, E, C>,
context: Context
) -> Result<Loc<Self, F>, Loc<Error<E, F>, F>> where
C: Iterator<Item = Result<DecodedChar, E>>,
fn parse<E, C>(file: F, chars: C) -> Result<Loc<Self, F>, Loc<Error<E, F>, F>> where
C: Iterator<Item = Result<DecodedChar, E>>,
fn parse_with<E, C>(
file: F,
chars: C,
options: Options
) -> Result<Loc<Self, F>, Loc<Error<E, F>, F>> where
C: Iterator<Item = Result<DecodedChar, E>>,
sourceimpl<M: PartialOrd> PartialOrd<Value<M>> for Value<M>
impl<M: PartialOrd> PartialOrd<Value<M>> for Value<M>
sourcefn partial_cmp(&self, other: &Value<M>) -> Option<Ordering>
fn partial_cmp(&self, other: &Value<M>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn 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 more
sourceimpl<M> PrecomputeSize for Value<M>
impl<M> PrecomputeSize for Value<M>
sourceimpl<M> Print for Value<M>
impl<M> Print for Value<M>
fn fmt_with(
&self,
f: &mut Formatter<'_>,
options: &Options,
indent: usize
) -> Result
sourcefn pretty_print(&self) -> Printed<'_, Self>
fn pretty_print(&self) -> Printed<'_, Self>
Print the value with Options::pretty
options.
sourcefn compact_print(&self) -> Printed<'_, Self>
fn compact_print(&self) -> Printed<'_, Self>
Print the value with Options::compact
options.
sourcefn inline_print(&self) -> Printed<'_, Self>
fn inline_print(&self) -> Printed<'_, Self>
Print the value with Options::inline
options.
sourcefn print_with(&self, options: Options) -> Printed<'_, Self>
fn print_with(&self, options: Options) -> Printed<'_, Self>
Print the value with the given options.
sourceimpl<M> PrintWithSize for Value<M>
impl<M> PrintWithSize for Value<M>
sourceimpl<M> StrippedHash for Value<M>
impl<M> StrippedHash for Value<M>
fn stripped_hash<H: Hasher>(&self, state: &mut H)
sourceimpl<M> StrippedOrd for Value<M>
impl<M> StrippedOrd for Value<M>
fn stripped_cmp(&self, other: &Self) -> Ordering
sourceimpl<M> StrippedPartialEq<Value<M>> for Value<M>
impl<M> StrippedPartialEq<Value<M>> for Value<M>
fn stripped_eq(&self, other: &Self) -> bool
sourceimpl<M> StrippedPartialOrd<Value<M>> for Value<M>
impl<M> StrippedPartialOrd<Value<M>> for Value<M>
fn stripped_partial_cmp(&self, other: &Self) -> Option<Ordering>
sourceimpl<M, N, E> TryMapMetadataRecursively<M, N, E> for Value<M>
impl<M, N, E> TryMapMetadataRecursively<M, N, E> for Value<M>
impl<M: Eq> Eq for Value<M>
impl<M> StrippedEq for Value<M>
impl<M> StructuralEq for Value<M>
impl<M> StructuralPartialEq for Value<M>
Auto Trait Implementations
impl<M> RefUnwindSafe for Value<M> where
M: RefUnwindSafe,
impl<M> Send for Value<M> where
M: Send,
impl<M> Sync for Value<M> where
M: Sync,
impl<M> Unpin for Value<M> where
M: Unpin,
impl<M> UnwindSafe for Value<M> where
M: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more