@@ -2,7 +2,7 @@ use crate::sys::*;
22use num_traits:: cast:: FromPrimitive ;
33use std:: { ffi:: CStr , os:: raw:: c_int} ;
44
5- #[ derive( FromPrimitive , PartialEq ) ]
5+ #[ derive( FromPrimitive , PartialEq , Clone , Copy ) ]
66#[ repr( u32 ) ]
77#[ non_exhaustive]
88pub enum Type {
@@ -24,6 +24,53 @@ pub enum Type {
2424 IsCallable = IS_CALLABLE ,
2525}
2626
27+ impl Type {
28+ #[ inline]
29+ pub fn is_null ( self ) -> bool {
30+ self == Type :: Null
31+ }
32+
33+ #[ inline]
34+ pub fn is_bool ( self ) -> bool {
35+ matches ! ( self , Type :: True | Type :: False )
36+ }
37+
38+ #[ inline]
39+ pub fn is_true ( self ) -> bool {
40+ self == Type :: True
41+ }
42+
43+ #[ inline]
44+ pub fn is_false ( self ) -> bool {
45+ self == Type :: False
46+ }
47+
48+ #[ inline]
49+ pub fn is_long ( self ) -> bool {
50+ self == Type :: Long
51+ }
52+
53+ #[ inline]
54+ pub fn is_double ( self ) -> bool {
55+ self == Type :: Double
56+ }
57+
58+ #[ inline]
59+ pub fn is_string ( self ) -> bool {
60+ matches ! ( self , Type :: String | Type :: StringEx )
61+ }
62+
63+ #[ inline]
64+ pub fn is_array ( self ) -> bool {
65+ matches ! ( self , Type :: Array | Type :: ArrayEx )
66+ }
67+
68+ #[ inline]
69+ pub fn is_object ( self ) -> bool {
70+ matches ! ( self , Type :: Object | Type :: ObjectEx )
71+ }
72+ }
73+
2774impl From < u32 > for Type {
2875 fn from ( n : u32 ) -> Self {
2976 match FromPrimitive :: from_u32 ( n) {
0 commit comments