Enum expry::DecodedValue

source ·
pub enum DecodedValue<'a> {
    Null,
    Bool(bool),
    Int(i64),
    Float(f32),
    Double(f64),
    String(&'a [u8]),
    Array(DecodedArray<'a>),
    Object(DecodedObject<'a>),
}
Expand description

The central data type of expry. It is modelled similar to JSON, however, contains a couple of noteworthy differences.

The differences with JSON:

  • There is an explicit integer type;
  • Floats are either 32-bits or 64-bits;
  • All strings are u8: they can contain both text or binary data.

To convert DecodedValue to JSON, one can use the formatting options like:

use expry::*;
let value = value!({"foo": 42});
let output = format!("JSON output: {}", value);
assert_eq!(output, r#"JSON output: {"foo":42}"#);

Variants§

§

Null

§

Bool(bool)

§

Int(i64)

Signed 64-bits integer (that is packed into smaller value in the wire format if possible).

§

Float(f32)

32-bits float type.

§

Double(f64)

64-bits float type.

§

String(&'a [u8])

Can be both binary data as regular strings. So not necessary UTF-8 (like Rust strings).

§

Array(DecodedArray<'a>)

§

Object(DecodedObject<'a>)

Implementations§

source§

impl<'a> DecodedValue<'a>

source

pub fn is_valid_json(&self) -> bool

source§

impl<'a> DecodedValue<'a>

source

pub const fn type_string(&self) -> &'static str

source

pub fn size_of_binary(&self) -> usize

Returns the size needed if we serialize the Binary to a binary wire-format. See DecodedValue::print_binary() for explanation of the compact argument.

source

pub fn print_binary<E, Out: RawOutput<E>>( &self, writer: &mut Out ) -> Result<(), E>

Converts a Binary to a wire representation of that Binary. This wire representation can be sent to other implementations as it is stable and ‘endian safe’.

For objects we have a compact representation and one that inserts hints how to process the wire-representation faster when using an expression to evaluate the Binary to another value. This is controlled with the compact argument.

This function expects that the writer has enough room. The needed room can be queried beforehand by using the DecodedValue::size_of_binary.

source

pub fn encode_to_vec(&self) -> EncodedValueVec

Converts a Binary to a wire representation of that Binary, in a self contained EncodedValueVec unsing DecodedValue::print_binary.

source

pub fn encode_to_scope<'c>( &self, scope: &mut MemoryScope<'c> ) -> EncodedValueRef<'c>

Converts a Binary to a wire representation of that Binary, in a self contained EncodedValueVec unsing DecodedValue::print_binary.

source

pub fn print_json(&self, writer: &mut String) -> Result<(), Utf8Error>

Convert a Binary value to a JSON output.

Note that some Binary values can not be encoded, because not all strings can be encoded as UTF-8. If this is the case, this method will result in a Utf8Error. If non-UTF8 data needs to be ignored, use format!("{}", decoded_value) or similar methods.

source

pub fn easy(&'a self) -> Easy<'a>

source§

impl<'a> DecodedValue<'a>

source

pub fn decoded_type_of(type_and_length: u64) -> Result<ValueType, EncodingError>

source

pub const fn type_of_binary(type_and_length: u64) -> u8

Based on a variable length integer read for the wire, return the ValueType raw number.

source

pub const fn length_of_binary(type_and_length: u64) -> usize

Based on a variable length integer read for the wire, return the length of the current entry.

source

pub fn decoded_type_and_length( type_and_length: u64 ) -> Result<(ValueType, usize), EncodingError>

source

pub fn decode<'b>( reader: &mut RawReader<'a> ) -> Result<DecodedValue<'b>, EncodingError>
where 'a: 'b,

Parse the wire-format. Note that although the input is malformed, it can still work out (keys of objects are not properly sorted, will not have an impact).

source

pub fn valid(reader: &mut RawReader<'a>) -> Result<(), EncodingError>

source§

impl<'a> DecodedValue<'a>

source

pub fn parse_json<'b, 'c>( reader: &'a str, allocator: &mut MemoryScope<'c> ) -> Result<DecodedValue<'b>, CompileError<'b>>
where 'c: 'b, 'a: 'b,

source

pub fn parse_expression_to_value<'c>( reader: &'a str, scope: &mut MemoryScope<'c> ) -> Result<DecodedValue<'a>, CompileError<'a>>
where 'c: 'a,

Trait Implementations§

source§

impl<'a> Clone for DecodedValue<'a>

source§

fn clone(&self) -> DecodedValue<'a>

Returns a copy 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<'a, 'b, 'c> CloneInMemoryScope<'c, DecodedValue<'b>> for DecodedValue<'a>
where 'c: 'b,

source§

fn clone_in(&self, scope: &mut MemoryScope<'c>) -> DecodedValue<'b>

source§

impl<'a> Debug for DecodedValue<'a>

source§

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

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

impl<'a> Default for DecodedValue<'a>

source§

fn default() -> DecodedValue<'a>

Returns the “default value” for a type. Read more
source§

impl<'a> Display for DecodedValue<'a>

source§

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

Silently ignores non-UTF8 data in strings. If an error is needed, use DecodedValue::print_json.

source§

impl<'a, T> From<&'a &'a [T]> for DecodedValue<'a>
where DecodedValue<'a>: From<&'a T>,

source§

fn from(v: &'a &'a [T]) -> Self

Converts to this type from the input type.
source§

impl<'a, T, const N: usize> From<&'a &'a [T; N]> for DecodedValue<'a>
where DecodedValue<'a>: From<&'a T>, T: Clone + 'a,

source§

fn from(v: &'a &'a [T; N]) -> Self

Converts to this type from the input type.
source§

impl<'a, 'b> From<&'b &'a String> for DecodedValue<'a>

source§

fn from(v: &'b &'a String) -> Self

Converts to this type from the input type.
source§

impl<'a, 'b> From<&'b &'a str> for DecodedValue<'a>

source§

fn from(v: &'b &'a str) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a [u8]> for DecodedValue<'a>

source§

fn from(v: &'a [u8]) -> Self

Converts to this type from the input type.
source§

impl<'a, const N: usize> From<&'a [u8; N]> for DecodedValue<'a>

source§

fn from(v: &'a [u8; N]) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&BytecodeRef<'a>> for DecodedValue<'a>

source§

fn from(v: &BytecodeRef<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a BytecodeVec> for DecodedValue<'a>

source§

fn from(v: &'a BytecodeVec) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&DecodedValue<'a>> for DecodedValue<'a>

source§

fn from(v: &DecodedValue<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a, T: 'a> From<&'a Option<T>> for DecodedValue<'a>
where DecodedValue<'a>: From<&'a T>,

source§

fn from(v: &'a Option<T>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a String> for DecodedValue<'a>

source§

fn from(v: &'a String) -> Self

Converts to this type from the input type.
source§

impl<'a, T> From<&'a Vec<T>> for DecodedValue<'a>
where DecodedValue<'a>: From<&'a T>,

source§

fn from(v: &'a Vec<T>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a Vec<u8>> for DecodedValue<'a>

source§

fn from(v: &'a Vec<u8>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&bool> for DecodedValue<'a>

source§

fn from(v: &bool) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&f32> for DecodedValue<'a>

source§

fn from(v: &f32) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&f64> for DecodedValue<'a>

source§

fn from(v: &f64) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&i64> for DecodedValue<'a>

source§

fn from(v: &i64) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a mut [u8]> for DecodedValue<'a>

source§

fn from(v: &'a mut [u8]) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a mut str> for DecodedValue<'a>

source§

fn from(v: &'a mut str) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for DecodedValue<'a>

source§

fn from(v: &'a str) -> Self

Converts to this type from the input type.
source§

impl<'a> PartialEq for DecodedValue<'a>

source§

fn eq(&self, other: &DecodedValue<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialOrd for DecodedValue<'a>

source§

fn partial_cmp(&self, other: &DecodedValue<'a>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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 · source§

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
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a> StructuralPartialEq for DecodedValue<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for DecodedValue<'a>

§

impl<'a> Send for DecodedValue<'a>

§

impl<'a> Sync for DecodedValue<'a>

§

impl<'a> Unpin for DecodedValue<'a>

§

impl<'a> UnwindSafe for DecodedValue<'a>

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.