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
impl Datum
Sourcepub fn from_json(v: &Value) -> Self
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).
Sourcepub fn from_cbor(v: &Value) -> Option<Self>
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.
Sourcepub fn from_json_bytes(bytes: &[u8]) -> Option<Self>
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.
Sourcepub fn from_cbor_bytes(bytes: &[u8]) -> Option<Self>
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.
Sourcepub fn decode(bytes: &[u8], encoding: Option<Encoding>) -> Option<Self>
pub fn decode(bytes: &[u8], encoding: Option<Encoding>) -> Option<Self>
A sample’s bytes as encoding carries them: JSON unless CBOR.
Sourcepub fn attachment(bytes: &[u8], encoding: Option<Encoding>) -> Self
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§
impl StructuralPartialEq for Datum
Auto Trait Implementations§
impl Forget for Datum
impl Freeze for Datumwhere
*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
impl Sync for Datum
impl Unpin for Datum
impl UnsafeUnpin for Datumwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<Datum>: UnsafeUnpin,
*const LeafNode<String, Datum> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, Datum)>>: UnsafeUnpin,
impl UnwindSafe for Datum
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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