[][src]Enum kiwi_schema::Value

pub enum Value<'a> {
    Bool(bool),
    Byte(u8),
    Int(i32),
    UInt(u32),
    Float(f32),
    String(String),
    Array(Vec<Value<'a>>),
    Enum(&'a str, &'a str),
    Object(&'a strHashMap<&'a str, Value<'a>>),
}

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)
Array(Vec<Value<'a>>)
Enum(&'a str, &'a str)
Object(&'a strHashMap<&'a str, Value<'a>>)

Implementations

impl<'a> Value<'a>[src]

pub fn as_bool(&self) -> bool[src]

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

pub fn as_byte(&self) -> u8[src]

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

pub fn as_int(&self) -> i32[src]

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

pub fn as_uint(&self) -> u32[src]

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

pub fn as_float(&self) -> f32[src]

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

pub fn as_string(&self) -> &str[src]

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

pub fn len(&self) -> usize[src]

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

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

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

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

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

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

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

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

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

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

Decodes the type specified by type_id and schema from bytes.

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

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

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

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.

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

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.

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

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

impl<'a> Clone for Value<'a>[src]

impl<'a> Debug for Value<'a>[src]

impl<'a> Index<usize> for Value<'a>[src]

type Output = Value<'a>

The returned type after indexing.

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

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.

impl<'a> PartialEq<Value<'a>> for Value<'a>[src]

impl<'a> StructuralPartialEq for Value<'a>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.