1
1
use crate :: {
2
2
error:: Error ,
3
3
ffi:: {
4
- FLArray , FLArray_Count , FLArray_Get , FLArray_IsEmpty , FLValue , FLValueType ,
5
- FLValue_AsArray , FLValue_AsBool , FLValue_AsDouble , FLValue_AsInt , FLValue_AsString ,
6
- FLValue_AsUnsigned , FLValue_GetType , FLValue_IsDouble , FLValue_IsInteger ,
7
- FLValue_IsUnsigned ,
4
+ FLArray , FLArray_Count , FLArray_Get , FLArray_IsEmpty , FLDict , FLDict_Count , FLDict_IsEmpty ,
5
+ FLValue , FLValueType , FLValue_AsArray , FLValue_AsBool , FLValue_AsDict , FLValue_AsDouble ,
6
+ FLValue_AsInt , FLValue_AsString , FLValue_AsUnsigned , FLValue_GetType , FLValue_IsDouble ,
7
+ FLValue_IsInteger , FLValue_IsUnsigned ,
8
8
} ,
9
9
fl_slice:: fl_slice_to_str_unchecked,
10
10
Result ,
@@ -20,6 +20,7 @@ pub enum ValueRef<'a> {
20
20
Double ( f64 ) ,
21
21
String ( & ' a str ) ,
22
22
Array ( ValueRefArray ) ,
23
+ Dict ( ValueRefDict ) ,
23
24
}
24
25
25
26
impl ValueRef < ' _ > {
@@ -37,28 +38,29 @@ impl ValueRef<'_> {
37
38
}
38
39
}
39
40
40
- impl < ' a > Into < ValueRef < ' a > > for FLValue {
41
- fn into ( self ) -> ValueRef < ' a > {
41
+ impl < ' a > From < FLValue > for ValueRef < ' a > {
42
+ fn from ( value : FLValue ) -> ValueRef < ' a > {
42
43
use FLValueType :: * ;
43
- match unsafe { FLValue_GetType ( self ) } {
44
+ match unsafe { FLValue_GetType ( value ) } {
44
45
kFLUndefined | kFLNull => ValueRef :: Null ,
45
- kFLBoolean => ValueRef :: Bool ( unsafe { FLValue_AsBool ( self ) } ) ,
46
+ kFLBoolean => ValueRef :: Bool ( unsafe { FLValue_AsBool ( value ) } ) ,
46
47
kFLNumber => {
47
- if unsafe { FLValue_IsInteger ( self ) } {
48
- ValueRef :: SignedInt ( unsafe { FLValue_AsInt ( self ) } )
49
- } else if unsafe { FLValue_IsUnsigned ( self ) } {
50
- ValueRef :: UnsignedInt ( unsafe { FLValue_AsUnsigned ( self ) } )
48
+ if unsafe { FLValue_IsInteger ( value ) } {
49
+ ValueRef :: SignedInt ( unsafe { FLValue_AsInt ( value ) } )
50
+ } else if unsafe { FLValue_IsUnsigned ( value ) } {
51
+ ValueRef :: UnsignedInt ( unsafe { FLValue_AsUnsigned ( value ) } )
51
52
} else {
52
- assert ! ( unsafe { FLValue_IsDouble ( self ) } ) ;
53
- ValueRef :: Double ( unsafe { FLValue_AsDouble ( self ) } )
53
+ assert ! ( unsafe { FLValue_IsDouble ( value ) } ) ;
54
+ ValueRef :: Double ( unsafe { FLValue_AsDouble ( value ) } )
54
55
}
55
56
}
56
57
kFLString => {
57
- let s = unsafe { fl_slice_to_str_unchecked ( FLValue_AsString ( self ) ) } ;
58
+ let s = unsafe { fl_slice_to_str_unchecked ( FLValue_AsString ( value ) ) } ;
58
59
ValueRef :: String ( s)
59
60
}
60
- kFLArray => ValueRef :: Array ( ValueRefArray ( unsafe { FLValue_AsArray ( self ) } ) ) ,
61
- kFLData | kFLDict => unimplemented ! ( ) ,
61
+ kFLArray => ValueRef :: Array ( ValueRefArray ( unsafe { FLValue_AsArray ( value) } ) ) ,
62
+ kFLDict => ValueRef :: Dict ( ValueRefDict ( unsafe { FLValue_AsDict ( value) } ) ) ,
63
+ kFLData => unimplemented ! ( ) ,
62
64
}
63
65
}
64
66
}
@@ -82,6 +84,19 @@ impl ValueRefArray {
82
84
}
83
85
}
84
86
87
+ #[ derive( Debug , Clone , Copy ) ]
88
+ #[ repr( transparent) ]
89
+ pub struct ValueRefDict ( FLDict ) ;
90
+
91
+ impl ValueRefDict {
92
+ pub fn len ( & self ) -> u32 {
93
+ unsafe { FLDict_Count ( self . 0 ) }
94
+ }
95
+ pub fn is_empty ( & self ) -> bool {
96
+ unsafe { FLDict_IsEmpty ( self . 0 ) }
97
+ }
98
+ }
99
+
85
100
pub trait FromValueRef < ' a > : Sized {
86
101
fn column_result ( value : ValueRef < ' a > ) -> Result < Self > ;
87
102
}
0 commit comments