pub fn from_value(value: &Value) -> Result<Self, VmError> {
        return Ok(match value {
            Value::Unit => Self::Unit,
            Value::Byte(b) => Self::Byte(*b),
            Value::Char(c) => Self::Char(*c),
            Value::Bool(b) => Self::Bool(*b),
            Value::Integer(n) => Self::Integer(*n),
            Value::String(s) => {
                let s = s.borrow_ref()?;
                Self::String(StringKey::String((**s).into()))
            }
            Value::StaticString(s) => Self::String(StringKey::StaticString(s.clone())),
            Value::Option(option) => Self::Option(match &*option.borrow_ref()? {
                Some(some) => Some(Box::new(Self::from_value(some)?)),
                None => None,
            }),
            Value::Bytes(b) => {
                let b = b.borrow_ref()?;
                Self::Bytes((*b).clone())
            }
            Value::Vec(vec) => {
                let vec = vec.borrow_ref()?;
                let mut key_vec = vec::Vec::with_capacity(vec.len());

                for value in &*vec {
                    key_vec.push(Self::from_value(value)?);
                }

                Self::Vec(key_vec)
            }
            Value::Tuple(tuple) => {
                let tuple = tuple.borrow_ref()?;
                Self::Tuple(tuple_from_value(&*tuple)?)
            }
            Value::Variant(variant) => {
                let variant = variant.borrow_ref()?;

                let data = match &variant.data {
                    VariantData::Unit => VariantKeyData::Unit,
                    VariantData::Tuple(tuple) => VariantKeyData::Tuple(tuple_from_value(tuple)?),
                    VariantData::Struct(object) => {
                        VariantKeyData::Struct(struct_from_value(object)?)
                    }
                };

                Key::Variant(VariantKey {
                    rtti: variant.rtti.clone(),
                    data,
                })
            }
            value => {
                return Err(VmError::from(VmErrorKind::KeyNotSupported {
                    actual: value.type_info()?,
                }))
            }
        });

        fn tuple_from_value(tuple: &Tuple) -> Result<Box<[Key]>, VmError> {
            let mut output = vec::Vec::with_capacity(tuple.len());

            for value in tuple {
                output.push(Key::from_value(value)?);
            }

            Ok(output.into_boxed_slice())
        }

        fn struct_from_value(object: &Object) -> Result<Box<[(Box<str>, Key)]>, VmError> {
            let mut output = vec::Vec::with_capacity(object.len());

            for (key, value) in object {
                output.push((key.as_str().into(), Key::from_value(value)?));
            }

            Ok(output.into_boxed_slice())
        }
    }
/// Convert a value reference into a key.
Convert a value reference into a key.
Convert a value reference into a key .
pub fn from_value(value: &Value) -> Result<Self, VmError> {
        return Ok(match value {
            Value::Unit => Self::Unit,
            Value::Byte(b) => Self::Byte(*b),
            Value::Char(c) => Self::Char(*c),
            Value::Bool(b) => Self::Bool(*b),
            Value::Integer(n) => Self::Integer(*n),
            Value::String(s) => {
                let s = s.borrow_ref()?;
                Self::String(StringKey::String((**s).into()))
            }
            Value::StaticString(s) => Self::String(StringKey::StaticString(s.clone())),
            Value::Option(option) => Self::Option(match &*option.borrow_ref()? {
                Some(some) => Some(Box::new(Self::from_value(some)?)),
                None => None,
            }),
            Value::Bytes(b) => {
                let b = b.borrow_ref()?;
                Self::Bytes((*b).clone())
            }
            Value::Vec(vec) => {
                let vec = vec.borrow_ref()?;
                let mut key_vec = vec::Vec::with_capacity(vec.len());
                for value in &*vec {
                    key_vec.push(Self::from_value(value)?);
                }
                Self::Vec(key_vec)
            }
            Value::Tuple(tuple) => {
                let tuple = tuple.borrow_ref()?;
                Self::Tuple(tuple_from_value(&*tuple)?)
            }
            Value::Variant(variant) => {
                let variant = variant.borrow_ref()?;
                let data = match &variant.data {
                    VariantData::Unit => VariantKeyData::Unit,
                    VariantData::Tuple(tuple) => VariantKeyData::Tuple(tuple_from_value(tuple)?),
                    VariantData::Struct(object) => {
                        VariantKeyData::Struct(struct_from_value(object)?)
                    }
                };
                Key::Variant(VariantKey {
                    rtti: variant.rtti.clone(),
                    data,
                })
            }
            value => {
                return Err(VmError::from(VmErrorKind::KeyNotSupported {
                    actual: value.type_info()?,
                }))
            }
        });
        fn tuple_from_value(tuple: &Tuple) -> Result<Box<[Key]>, VmError> {
            let mut output = vec::Vec::with_capacity(tuple.len());
            for value in tuple {
                output.push(Key::from_value(value)?);
            }
            Ok(output.into_boxed_slice())
        }
        fn struct_from_value(object: &Object) -> Result<Box<[(Box<str>, Key)]>, VmError> {
            let mut output = vec::Vec::with_capacity(object.len());
            for (key, value) in object {
                output.push((key.as_str().into(), Key::from_value(value)?));
            }
            Ok(output.into_boxed_slice())
        }
    }
pub fn from_value ( value : & Value ) -> Result < Self , VmError > { return Ok ( match value { Value :: Unit => Self :: Unit , Value :: Byte ( b ) => Self :: Byte ( * b ) , Value :: Char ( c ) => Self :: Char ( * c ) , Value :: Bool ( b ) => Self :: Bool ( * b ) , Value :: Integer ( n ) => Self :: Integer ( * n ) , Value :: String ( s ) => { let s = s . borrow_ref ( ) ? ; Self :: String ( StringKey :: String ( ( * * s ) . into ( ) ) ) } Value :: StaticString ( s ) => Self :: String ( StringKey :: StaticString ( s . clone ( ) ) ) , Value :: Option ( option ) => Self :: Option ( match & * option . borrow_ref ( ) ? { Some ( some ) => Some ( Box :: new ( Self :: from_value ( some ) ? ) ) , None => None , } ) , Value :: Bytes ( b ) => { let b = b . borrow_ref ( ) ? ; Self :: Bytes ( ( * b ) . clone ( ) ) } Value :: Vec ( vec ) => { let vec = vec . borrow_ref ( ) ? ; let mut key_vec = vec :: Vec :: with_capacity ( vec . len ( ) ) ; for value in & * vec { key_vec . push ( Self :: from_value ( value ) ? ) ; } Self :: Vec ( key_vec ) } Value :: Tuple ( tuple ) => { let tuple = tuple . borrow_ref ( ) ? ; Self :: Tuple ( tuple_from_value ( & * tuple ) ? ) } Value :: Variant ( variant ) => { let variant = variant . borrow_ref ( ) ? ; let data = match & variant . data { VariantData :: Unit => VariantKeyData :: Unit , VariantData :: Tuple ( tuple ) => VariantKeyData :: Tuple ( tuple_from_value ( tuple ) ? ) , VariantData :: Struct ( object ) => { VariantKeyData :: Struct ( struct_from_value ( object ) ? ) } } ; Key :: Variant ( VariantKey { rtti : variant . rtti . clone ( ) , data , } ) } value => { return Err ( VmError :: from ( VmErrorKind :: KeyNotSupported { actual : value . type_info ( ) ? , } ) ) } } ) ; fn tuple_from_value ( tuple : & Tuple ) -> Result < Box < [ Key ] > , VmError > { let mut output = vec :: Vec :: with_capacity ( tuple . len ( ) ) ; for value in tuple { output . push ( Key :: from_value ( value ) ? ) ; } Ok ( output . into_boxed_slice ( ) ) } fn struct_from_value ( object : & Object ) -> Result < Box < [ ( Box < str > , Key ) ] > , VmError > { let mut output = vec :: Vec :: with_capacity ( object . len ( ) ) ; for ( key , value ) in object { output . push ( ( key . as_str ( ) . into ( ) , Key :: from_value ( value ) ? ) ) ; } Ok ( output . into_boxed_slice ( ) ) } }
Convert a value reference into a key.
Convert a value reference into a key .
value
&Value
value
&Value