Enum Json

Source
pub enum Json {
    Null,
    Bool(bool),
    Num(f64),
    Str(String),
    Arr(Vec<Json>),
    Obj(BTreeMap<String, Json>),
}
Expand description

A JSON value held in memory, as the catalog manipulates it between the file and the model.

Variants§

§

Null

The null literal, which the catalog uses for an absent or unknown field.

§

Bool(bool)

The true and false literals.

§

Num(f64)

A number: JSON knows only one numeric type, kept here as a double.

§

Str(String)

A text string, already unescaped: the characters it denotes, not its written form.

§

Arr(Vec<Json>)

An ordered sequence of values, the JSON array; a table of the schema is one of these.

§

Obj(BTreeMap<String, Json>)

A set of key/value pairs, kept sorted by key so that two writes give the same bytes.

Implementations§

Source§

impl Json

Source

pub fn obj() -> Json

Opens an empty object, the starting point for building a row field by field.

Source

pub fn set(&mut self, key: &str, value: Json)

Adds or replaces a field. The call is silently ignored when the value is not an object.

Source

pub fn get(&self, key: &str) -> Option<&Json>

Looks up a field by name; absent key and non-object alike give None, without failing.

Source

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

Borrows the text of a string value, with no copy; anything else gives None.

Source

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

Same reading as Json::as_str, copied out for a caller that needs to keep the text.

Source

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

Reads a number as stored, with no conversion or rounding.

Source

pub fn as_u64(&self) -> Option<u64>

Reads an integral, finite count in the u64 range. Fractional and out-of-range values are refused instead of being rounded or clamped.

Source

pub fn as_u32(&self) -> Option<u32>

Same reading as Json::as_u64, narrowed for the small counters of the schema such as a year or a track number.

Source

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

Reads a boolean value; a 0 or a "true" string is not accepted as one.

Source

pub fn as_arr(&self) -> Option<&[Json]>

Borrows the elements of an array, the usual way to walk over the rows of a table.

Source

pub fn field_str(&self, key: &str) -> Option<String>

Direct access to a typed field, tolerating a missing key.

Source

pub fn field_u64(&self, key: &str) -> Option<u64>

Reads a field as a count, absent or unusable giving None.

Source

pub fn field_u32(&self, key: &str) -> Option<u32>

Reads a field as a small count, absent or unusable giving None.

Source

pub fn field_f64(&self, key: &str) -> Option<f64>

Reads a numeric field that may be fractional.

Source

pub fn field_optional_bool(&self, key: &str) -> Option<bool>

Reads a boolean field, None when it is absent or of another type.

Distinct from Json::field_bool, which answers false for both: an imported measurement that was never taken is not a measurement that came out negative.

Source

pub fn field_bool(&self, key: &str) -> bool

Reads a flag, where an absent field means false: an older catalog that predates the flag is read without special handling.

Source§

impl Json

Source

pub fn to_string_compact(&self) -> String

Serializes to compact JSON.

Source

pub fn to_string_pretty(&self) -> String

Serializes to indented JSON, easier to inspect by hand.

Trait Implementations§

Source§

impl Clone for Json

Source§

fn clone(&self) -> Json

Returns a duplicate 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 Json

Source§

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

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

impl From<&str> for Json

Source§

fn from(s: &str) -> Json

Converts to this type from the input type.
Source§

impl<T: Into<Json>> From<Option<T>> for Json

Source§

fn from(v: Option<T>) -> Json

Converts to this type from the input type.
Source§

impl From<String> for Json

Source§

fn from(s: String) -> Json

Converts to this type from the input type.
Source§

impl<T: Into<Json>> From<Vec<T>> for Json

Source§

fn from(v: Vec<T>) -> Json

Converts to this type from the input type.
Source§

impl From<bool> for Json

Source§

fn from(b: bool) -> Json

Converts to this type from the input type.
Source§

impl From<f64> for Json

Source§

fn from(n: f64) -> Json

Converts to this type from the input type.
Source§

impl From<i64> for Json

Source§

fn from(n: i64) -> Json

Converts to this type from the input type.
Source§

impl From<u32> for Json

Source§

fn from(n: u32) -> Json

Converts to this type from the input type.
Source§

impl From<u64> for Json

Source§

fn from(n: u64) -> Json

Converts to this type from the input type.
Source§

impl From<usize> for Json

Source§

fn from(n: usize) -> Json

Converts to this type from the input type.
Source§

impl PartialEq for Json

Source§

fn eq(&self, other: &Json) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Json

Auto Trait Implementations§

§

impl Freeze for Json

§

impl RefUnwindSafe for Json

§

impl Send for Json

§

impl Sync for Json

§

impl Unpin for Json

§

impl UnwindSafe for Json

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where 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.

§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,