Skip to main content

Datum

Enum Datum 

Source
pub enum Datum {
    Null,
    Bool(bool),
    Int(i128),
    BigInt(f64),
    Float(f64),
    Text(String),
    Bytes(Vec<u8>),
    Array(Vec<Datum>),
    Map(BTreeMap<String, Datum>),
}
Expand description

A sample’s decoded data item (§2.6): JSON’s data model, plus what CBOR adds, byte strings and non-finite floats. Integers are exact.

Variants§

§

Null

§

Bool(bool)

§

Int(i128)

An integer: JSON text with no fraction and no exponent, CBOR’s major types 0 and 1, or a bignum (tags 2 and 3, 0.2).

§

BigInt(f64)

An integer beyond i128 (0.2): JSON text within the double’s finite range, or a CBOR bignum of any length, held as its nearest double (infinite past the double’s range). No range of §2.6 admits one: as an integer it reads beyond every bound, as a number it is that double.

§

Float(f64)

A float: JSON text with a fraction or an exponent, a CBOR float.

§

Text(String)

§

Bytes(Vec<u8>)

§

Array(Vec<Datum>)

§

Map(BTreeMap<String, Datum>)

Implementations§

Source§

impl Datum

Source

pub fn from_json(v: &Value) -> Self

A JSON value as a datum: an integer JSON number exactly, any other as its double. serde_json holds no integer beyond 64 bits, and keeps the last of two duplicate members: a sample’s bytes are read by Datum::from_json_bytes, strict JSON (§2.6, 0.2).

Source

pub fn from_cbor(v: &Value) -> Option<Self>

A CBOR data item as a datum, keeping byte strings and non-finite floats (§2.6); a tag reads as its content. None for a map key that is not text, or a value with no datum.

Source

pub fn from_json_bytes(bytes: &[u8]) -> Option<Self>

One JSON text, as strict JSON reads it (§2.6, 0.2; decode::json): None when the bytes are not one, the sample undecodable.

Source

pub fn from_cbor_bytes(bytes: &[u8]) -> Option<Self>

One CBOR data item and nothing after it, its bignums integers (§2.6, 0.2; decode::cbor): None when the bytes are not one.

Source

pub fn decode(bytes: &[u8], encoding: Option<Encoding>) -> Option<Self>

A sample’s bytes as encoding carries them: JSON unless CBOR.

Source

pub fn attachment(bytes: &[u8], encoding: Option<Encoding>) -> Self

An attachment’s bytes as the datum a reader checks (§2.6 check 2, 0.2): decoded as encoding carries it, or, when they do not decode, the bytes themselves, which are no string, so an Epoch attachment that does not decode is an epoch present and not a string: epoch_invalid, the sample still read. Zero bytes are such an attachment.

Trait Implementations§

Source§

impl Clone for Datum

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Datum

Source§

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

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

impl PartialEq for Datum

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Datum

Auto Trait Implementations§

§

impl Forget for Datum

§

impl Freeze for Datum
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<Datum>: Freeze, *const LeafNode<String, Datum> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, Datum)>>: Freeze,

§

impl Move for Datum

§

impl RefUnwindSafe for Datum

§

impl Send for Datum
where RawVecInner: Send, NodeRef<Owned, String, Datum, LeafOrInternal>: Send, BoxRaw<(String, Datum)>: Send,

§

impl Sync for Datum
where RawVecInner: Sync, NodeRef<Owned, String, Datum, LeafOrInternal>: Sync, BoxRaw<(String, Datum)>: Sync,

§

impl Unpin for Datum
where *const u8 is !null: Unpin, *const LeafNode<String, Datum> is !null: Unpin, Box<(String, Datum)>: Unpin,

§

impl UnsafeUnpin for Datum

§

impl UnwindSafe for Datum
where RawVecInner: UnwindSafe, BTreeMap<String, Datum>: UnwindSafe,

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> AsNode<T> for T

Source§

fn as_node(&self) -> &T

Source§

impl<T> AsNodeMut<T> for T

Source§

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

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.