1- use std:: borrow:: Cow ;
2-
31use crate :: any:: { Any , AnyTypeInfo , AnyTypeInfoKind } ;
42use crate :: database:: Database ;
53use crate :: error:: BoxDynError ;
64use crate :: types:: Type ;
75use crate :: value:: { Value , ValueRef } ;
6+ use std:: borrow:: Cow ;
7+ use std:: sync:: Arc ;
88
99#[ derive( Clone , Debug ) ]
1010#[ non_exhaustive]
11- pub enum AnyValueKind < ' a > {
11+ pub enum AnyValueKind {
1212 Null ( AnyTypeInfoKind ) ,
1313 Bool ( bool ) ,
1414 SmallInt ( i16 ) ,
1515 Integer ( i32 ) ,
1616 BigInt ( i64 ) ,
1717 Real ( f32 ) ,
1818 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 > > ) ,
2122}
2223
23- impl AnyValueKind < ' _ > {
24+ impl AnyValueKind {
2425 fn type_info ( & self ) -> AnyTypeInfo {
2526 AnyTypeInfo {
2627 kind : match self {
@@ -32,6 +33,7 @@ impl AnyValueKind<'_> {
3233 AnyValueKind :: Real ( _) => AnyTypeInfoKind :: Real ,
3334 AnyValueKind :: Double ( _) => AnyTypeInfoKind :: Double ,
3435 AnyValueKind :: Text ( _) => AnyTypeInfoKind :: Text ,
36+ AnyValueKind :: TextSlice ( _) => AnyTypeInfoKind :: Text ,
3537 AnyValueKind :: Blob ( _) => AnyTypeInfoKind :: Blob ,
3638 } ,
3739 }
@@ -60,31 +62,19 @@ impl AnyValueKind<'_> {
6062#[ derive( Clone , Debug ) ]
6163pub struct AnyValue {
6264 #[ doc( hidden) ]
63- pub kind : AnyValueKind < ' static > ,
65+ pub kind : AnyValueKind ,
6466}
6567
6668#[ derive( Clone , Debug ) ]
6769pub struct AnyValueRef < ' a > {
68- pub ( crate ) kind : AnyValueKind < ' a > ,
70+ pub ( crate ) kind : & ' a AnyValueKind ,
6971}
7072
7173impl Value for AnyValue {
7274 type Database = Any ;
7375
7476 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 }
8878 }
8979
9080 fn type_info ( & self ) -> Cow < ' _ , <Self :: Database as Database >:: TypeInfo > {
@@ -101,17 +91,7 @@ impl<'a> ValueRef<'a> for AnyValueRef<'a> {
10191
10292 fn to_owned ( & self ) -> <Self :: Database as Database >:: Value {
10393 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 ( ) ,
11595 }
11696 }
11797
0 commit comments