Enum kiwi_schema::Value

source ·
pub enum Value<'a> {
    Bool(bool),
    Byte(u8),
    Int(i32),
    UInt(u32),
    Float(f32),
    String(String),
    Int64(i64),
    UInt64(u64),
    Array(Vec<Value<'a>>),
    Enum(&'a str, &'a str),
    Object(&'a str, HashMap<&'a str, Value<'a>>),
}
Expand description

This type holds dynamic Kiwi data.

Values can represent anything in a Kiwi schema and can be converted to and from byte arrays using the corresponding Schema. Enums and field names are stored using string slices from their Schema for efficiency. This means that a Value can outlive the buffer it was parsed from but can’t outlive the schema.

Variants§

§

Bool(bool)

§

Byte(u8)

§

Int(i32)

§

UInt(u32)

§

Float(f32)

§

String(String)

§

Int64(i64)

§

UInt64(u64)

§

Array(Vec<Value<'a>>)

§

Enum(&'a str, &'a str)

§

Object(&'a str, HashMap<&'a str, Value<'a>>)

Implementations§

source§

impl<'a> Value<'a>

source

pub fn as_bool(&self) -> bool

A convenience method to extract the value out of a Bool. Returns false for other value kinds.

source

pub fn as_byte(&self) -> u8

A convenience method to extract the value out of a Byte. Returns 0 for other value kinds.

source

pub fn as_int(&self) -> i32

A convenience method to extract the value out of an Int. Returns 0 for other value kinds.

source

pub fn as_uint(&self) -> u32

A convenience method to extract the value out of a UInt. Returns 0 for other value kinds.

source

pub fn as_float(&self) -> f32

A convenience method to extract the value out of a Float. Returns 0.0 for other value kinds.

source

pub fn as_string(&self) -> &str

A convenience method to extract the value out of a String. Returns "" for other value kinds.

source

pub fn len(&self) -> usize

A convenience method to extract the length out of an Array. Returns 0 for other value kinds.

source

pub fn push(&mut self, value: Value<'a>)

A convenience method to append to an Array. Does nothing for other value kinds.

source

pub fn get(&self, name: &str) -> Option<&Value<'a>>

A convenience method to extract a field out of an Object. Returns None for other value kinds or if the field isn’t present.

source

pub fn set(&mut self, name: &'a str, value: Value<'a>)

A convenience method to update a field on an Object. Does nothing for other value kinds.

source

pub fn remove(&mut self, name: &'a str)

A convenience method to remove a field on an Object. Does nothing for other value kinds.

source

pub fn decode( schema: &'a Schema, type_id: i32, bytes: &[u8] ) -> Result<Value<'a>, ()>

Decodes the type specified by type_id and schema from bytes.

source

pub fn encode(&self, schema: &Schema) -> Vec<u8>

Encodes this value into an array of bytes using the provided schema.

source

pub fn decode_bb( schema: &'a Schema, type_id: i32, bb: &mut ByteBuffer<'_> ) -> Result<Value<'a>, ()>

Decodes the type specified by type_id and schema from bb starting at the current index. After this function returns, the current index will be advanced by the amount of data that was successfully parsed. This is mainly useful as a helper routine for decode, which you probably want to use instead.

source

pub fn decode_field_bb( schema: &'a Schema, field: &Field, bb: &mut ByteBuffer<'_> ) -> Result<Value<'a>, ()>

Decodes the field specified by field and schema from bb starting at the current index. This is used by decode_bb but may also be useful by itself.

source

pub fn encode_bb(&self, schema: &Schema, bb: &mut ByteBufferMut)

Encodes the current value to the end of bb using the provided schema. This is mainly useful as a helper routine for encode, which you probably want to use instead.

Trait Implementations§

source§

impl<'a> Clone for Value<'a>

source§

fn clone(&self) -> Value<'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> Debug for Value<'a>

source§

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

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

impl<'a> Index<usize> for Value<'a>

source§

fn index(&self, index: usize) -> &Value<'a>

A convenience method that adds support for self[index] expressions. It will panic if this value isn’t an Array or if the provided index is out of bounds.

§

type Output = Value<'a>

The returned type after indexing.
source§

impl<'a> PartialEq<Value<'a>> for Value<'a>

source§

fn eq(&self, other: &Value<'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> StructuralPartialEq for Value<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Value<'a>

§

impl<'a> Send for Value<'a>

§

impl<'a> Sync for Value<'a>

§

impl<'a> Unpin for Value<'a>

§

impl<'a> UnwindSafe for Value<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.