pub struct KeyValue {
pub id: Uuid,
pub fields: HashMap<String, KeyValueField>,
}Expand description
A collection of named KeyValueFields identified by a UUID.
§Construction
Use the provided From implementations. Supported conversions:
Vec<KeyValueField>->KeyValue[KeyValueField; N](array) ->KeyValueKeyValueSet->KeyValue(Uuid, Vec<KeyValueField>),(Uuid, [KeyValueField; N]),(Uuid, KeyValueSet)and(Uuid, HashMap<String, KeyValueField>)->KeyValuewith explicit id- Any
KeyValue->Valueviainto()
use arora_types::keyvalue::{KeyValue, KeyValueField, KeyValueItems};
use arora_types::value::Value;
use arora_types::gen_bb_uuid;
// From a Vec
let kv: KeyValue = vec![
KeyValueField::new("health", Value::I32(100)),
KeyValueField::new("mana", Value::I32(50)),
].into();
// From an array
let position: KeyValue = [
KeyValueField::new("x", Value::F32(1.0)),
KeyValueField::new("y", Value::F32(2.0)),
].into();
// Explicit id with a Vec
let id = gen_bb_uuid();
let kv_with_id: KeyValue = (id, vec![
KeyValueField::new("level", Value::I32(5)),
KeyValueField::new("xp", Value::I64(9000)),
]).into();
// Nested structure via helper
let stats_set = KeyValueItems::from(vec![
KeyValueField::new("strength", Value::I32(50)),
KeyValueField::new("agility", Value::I32(75)),
]);
let player: KeyValue = vec![
KeyValueField::new("health", Value::I32(100)),
KeyValueField::new_nested_kv("stats", &stats_set),
].into();
// Convert to Value only when needed
let value: Value = player.clone().into();
assert!(matches!(value, Value::KeyValue(_)));Fields§
§id: Uuid§fields: HashMap<String, KeyValueField>Implementations§
Source§impl KeyValue
impl KeyValue
pub fn new() -> Self
pub fn new_with_id(id: Uuid) -> Self
pub fn set_field(&mut self, field: KeyValueField)
pub fn set_field_value(&mut self, key: &str, value: Value)
pub fn get_fields(&self) -> &HashMap<String, KeyValueField>
pub fn get_field_keys(&self) -> Vec<String>
pub fn get_field(&self, key: &str) -> Option<&KeyValueField>
pub fn as_value(self) -> Value
Trait Implementations§
Source§impl<'de> Deserialize<'de> for KeyValue
impl<'de> Deserialize<'de> for KeyValue
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&[KeyValueField]> for KeyValue
impl From<&[KeyValueField]> for KeyValue
Source§fn from(fields: &[KeyValueField]) -> Self
fn from(fields: &[KeyValueField]) -> Self
Converts to this type from the input type.
Source§impl From<(Uuid, &[KeyValueField])> for KeyValue
impl From<(Uuid, &[KeyValueField])> for KeyValue
Source§fn from((id, fields): (Uuid, &[KeyValueField])) -> Self
fn from((id, fields): (Uuid, &[KeyValueField])) -> Self
Converts to this type from the input type.
Source§impl From<(Uuid, KeyValueItems)> for KeyValue
impl From<(Uuid, KeyValueItems)> for KeyValue
Source§fn from((id, set): (Uuid, KeyValueItems)) -> Self
fn from((id, set): (Uuid, KeyValueItems)) -> Self
Converts to this type from the input type.
Source§impl From<KeyValueItems> for KeyValue
impl From<KeyValueItems> for KeyValue
Source§fn from(set: KeyValueItems) -> Self
fn from(set: KeyValueItems) -> Self
Converts to this type from the input type.
Source§impl From<Vec<KeyValueField>> for KeyValue
impl From<Vec<KeyValueField>> for KeyValue
Source§fn from(fields: Vec<KeyValueField>) -> Self
fn from(fields: Vec<KeyValueField>) -> Self
Converts to this type from the input type.
Source§impl<const N: usize> From<[KeyValueField; N]> for KeyValue
impl<const N: usize> From<[KeyValueField; N]> for KeyValue
Source§fn from(arr: [KeyValueField; N]) -> Self
fn from(arr: [KeyValueField; N]) -> Self
Converts to this type from the input type.
impl StructuralPartialEq for KeyValue
Auto Trait Implementations§
impl Freeze for KeyValue
impl RefUnwindSafe for KeyValue
impl Send for KeyValue
impl Sync for KeyValue
impl Unpin for KeyValue
impl UnsafeUnpin for KeyValue
impl UnwindSafe for KeyValue
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
Mutably borrows from an owned value. Read more