Enum kiwi_schema::Value
[−]
[src]
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 str, HashMap<&'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 str, HashMap<&'a str, Value<'a>>)
Methods
impl<'a> Value<'a>
[src]
fn as_bool(&self) -> bool
[src]
A convenience method to extract the value out of a Bool.
Returns false
for other value kinds.
fn as_byte(&self) -> u8
[src]
A convenience method to extract the value out of a Byte.
Returns 0
for other value kinds.
fn as_int(&self) -> i32
[src]
A convenience method to extract the value out of an Int.
Returns 0
for other value kinds.
fn as_uint(&self) -> u32
[src]
A convenience method to extract the value out of a UInt.
Returns 0
for other value kinds.
fn as_float(&self) -> f32
[src]
A convenience method to extract the value out of a Float.
Returns 0.0
for other value kinds.
fn as_string(&self) -> &str
[src]
A convenience method to extract the value out of a String.
Returns ""
for other value kinds.
fn len(&self) -> usize
[src]
A convenience method to extract the length out of an Array.
Returns 0
for other value kinds.
fn get(&self, name: &str) -> Option<&Value>
[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.
fn decode(
schema: &'a Schema,
type_id: i32,
bytes: &[u8]
) -> Result<Value<'a>, ()>
[src]
schema: &'a Schema,
type_id: i32,
bytes: &[u8]
) -> Result<Value<'a>, ()>
Decodes the type specified by type_id
and schema
from bytes
.
fn encode(&self, schema: &Schema) -> Vec<u8>
[src]
Encodes this value into an array of bytes using the provided schema
.
fn decode_bb(
schema: &'a Schema,
type_id: i32,
bb: &mut ByteBuffer
) -> Result<Value<'a>, ()>
[src]
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.
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]
fn clone(&self) -> Value<'a>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a> PartialEq for Value<'a>
[src]
fn eq(&self, __arg_0: &Value<'a>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Value<'a>) -> bool
[src]
This method tests for !=
.
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.