1
- use std:: borrow:: Cow ;
2
-
3
1
use crate :: any:: { Any , AnyTypeInfo , AnyTypeInfoKind } ;
4
2
use crate :: database:: Database ;
5
3
use crate :: error:: BoxDynError ;
6
4
use crate :: types:: Type ;
7
5
use crate :: value:: { Value , ValueRef } ;
6
+ use std:: borrow:: Cow ;
7
+ use std:: sync:: Arc ;
8
8
9
9
#[ derive( Clone , Debug ) ]
10
10
#[ non_exhaustive]
11
- pub enum AnyValueKind < ' a > {
11
+ pub enum AnyValueKind {
12
12
Null ( AnyTypeInfoKind ) ,
13
13
Bool ( bool ) ,
14
14
SmallInt ( i16 ) ,
15
15
Integer ( i32 ) ,
16
16
BigInt ( i64 ) ,
17
17
Real ( f32 ) ,
18
18
Double ( f64 ) ,
19
- Text ( Cow < ' a , str > ) ,
20
- Blob ( Cow < ' a , [ u8 ] > ) ,
19
+ Text ( Arc < String > ) ,
20
+ TextSlice ( Arc < str > ) ,
21
+ Blob ( Arc < Vec < u8 > > ) ,
21
22
}
22
23
23
- impl AnyValueKind < ' _ > {
24
+ impl AnyValueKind {
24
25
fn type_info ( & self ) -> AnyTypeInfo {
25
26
AnyTypeInfo {
26
27
kind : match self {
@@ -32,6 +33,7 @@ impl AnyValueKind<'_> {
32
33
AnyValueKind :: Real ( _) => AnyTypeInfoKind :: Real ,
33
34
AnyValueKind :: Double ( _) => AnyTypeInfoKind :: Double ,
34
35
AnyValueKind :: Text ( _) => AnyTypeInfoKind :: Text ,
36
+ AnyValueKind :: TextSlice ( _) => AnyTypeInfoKind :: Text ,
35
37
AnyValueKind :: Blob ( _) => AnyTypeInfoKind :: Blob ,
36
38
} ,
37
39
}
@@ -60,31 +62,19 @@ impl AnyValueKind<'_> {
60
62
#[ derive( Clone , Debug ) ]
61
63
pub struct AnyValue {
62
64
#[ doc( hidden) ]
63
- pub kind : AnyValueKind < ' static > ,
65
+ pub kind : AnyValueKind ,
64
66
}
65
67
66
68
#[ derive( Clone , Debug ) ]
67
69
pub struct AnyValueRef < ' a > {
68
- pub ( crate ) kind : AnyValueKind < ' a > ,
70
+ pub ( crate ) kind : & ' a AnyValueKind ,
69
71
}
70
72
71
73
impl Value for AnyValue {
72
74
type Database = Any ;
73
75
74
76
fn as_ref ( & self ) -> <Self :: Database as Database >:: ValueRef < ' _ > {
75
- AnyValueRef {
76
- kind : match & self . kind {
77
- AnyValueKind :: Null ( k) => AnyValueKind :: Null ( * k) ,
78
- AnyValueKind :: Bool ( b) => AnyValueKind :: Bool ( * b) ,
79
- AnyValueKind :: SmallInt ( i) => AnyValueKind :: SmallInt ( * i) ,
80
- AnyValueKind :: Integer ( i) => AnyValueKind :: Integer ( * i) ,
81
- AnyValueKind :: BigInt ( i) => AnyValueKind :: BigInt ( * i) ,
82
- AnyValueKind :: Real ( r) => AnyValueKind :: Real ( * r) ,
83
- AnyValueKind :: Double ( d) => AnyValueKind :: Double ( * d) ,
84
- AnyValueKind :: Text ( t) => AnyValueKind :: Text ( Cow :: Borrowed ( t) ) ,
85
- AnyValueKind :: Blob ( b) => AnyValueKind :: Blob ( Cow :: Borrowed ( b) ) ,
86
- } ,
87
- }
77
+ AnyValueRef { kind : & self . kind }
88
78
}
89
79
90
80
fn type_info ( & self ) -> Cow < ' _ , <Self :: Database as Database >:: TypeInfo > {
@@ -101,17 +91,7 @@ impl<'a> ValueRef<'a> for AnyValueRef<'a> {
101
91
102
92
fn to_owned ( & self ) -> <Self :: Database as Database >:: Value {
103
93
AnyValue {
104
- kind : match & self . kind {
105
- AnyValueKind :: Null ( k) => AnyValueKind :: Null ( * k) ,
106
- AnyValueKind :: Bool ( b) => AnyValueKind :: Bool ( * b) ,
107
- AnyValueKind :: SmallInt ( i) => AnyValueKind :: SmallInt ( * i) ,
108
- AnyValueKind :: Integer ( i) => AnyValueKind :: Integer ( * i) ,
109
- AnyValueKind :: BigInt ( i) => AnyValueKind :: BigInt ( * i) ,
110
- AnyValueKind :: Real ( r) => AnyValueKind :: Real ( * r) ,
111
- AnyValueKind :: Double ( d) => AnyValueKind :: Double ( * d) ,
112
- AnyValueKind :: Text ( t) => AnyValueKind :: Text ( Cow :: Owned ( t. to_string ( ) ) ) ,
113
- AnyValueKind :: Blob ( b) => AnyValueKind :: Blob ( Cow :: Owned ( b. to_vec ( ) ) ) ,
114
- } ,
94
+ kind : self . kind . clone ( ) ,
115
95
}
116
96
}
117
97
0 commit comments