1+ use std:: borrow:: Cow ;
2+
13use chrono:: { DateTime , NaiveDate , NaiveDateTime , NaiveTime , Utc } ;
24use time:: { Date , OffsetDateTime , PrimitiveDateTime , Time } ;
35use uuid:: Uuid ;
46
7+ use crate :: cows:: VecCow ;
8+
59/// This enum represents a [Null](Value::Null)'s type
610#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
711pub enum NullType {
@@ -61,27 +65,27 @@ pub enum NullType {
6165/**
6266This enum represents a value
6367 */
64- #[ derive( Copy , Clone , Debug , PartialEq ) ]
68+ #[ derive( Clone , Debug , PartialEq ) ]
6569pub enum Value < ' a > {
6670 /// null representation
6771 Null ( NullType ) ,
6872 /// Representation of an identifier, e.g. a column.
6973 /// This variant will not be escaped, so do not
7074 /// pass unchecked data to it.
7175 #[ deprecated( note = "Is this still used?" ) ]
72- Ident ( & ' a str ) ,
76+ Ident ( Cow < ' a , str > ) ,
7377 /// Representation of a column name with
7478 /// an optional table name
7579 Column {
7680 /// Name of the table
77- table_name : Option < & ' a str > ,
81+ table_name : Option < Cow < ' a , str > > ,
7882 /// Name of the column
79- column_name : & ' a str ,
83+ column_name : Cow < ' a , str > ,
8084 } ,
8185 /// Representation of choices
82- Choice ( & ' a str ) ,
86+ Choice ( Cow < ' a , str > ) ,
8387 /// String representation
84- String ( & ' a str ) ,
88+ String ( Cow < ' a , str > ) ,
8589 /// i64 representation
8690 I64 ( i64 ) ,
8791 /// i32 representation
@@ -95,7 +99,7 @@ pub enum Value<'a> {
9599 /// f32 representation
96100 F32 ( f32 ) ,
97101 /// binary representation
98- Binary ( & ' a [ u8 ] ) ,
102+ Binary ( Cow < ' a , [ u8 ] > ) ,
99103 /// chrono's Naive Time representation
100104 ChronoNaiveTime ( NaiveTime ) ,
101105 /// chrono's Naive Date representation
@@ -131,73 +135,82 @@ pub enum Value<'a> {
131135 IpNetwork ( ipnetwork:: IpNetwork ) ,
132136 /// Bit vec representation
133137 #[ cfg( feature = "postgres-only" ) ]
134- BitVec ( & ' a bit_vec:: BitVec ) ,
138+ BitVec ( Cow < ' a , bit_vec:: BitVec > ) ,
135139
136140 /// null representation
137141 #[ cfg( feature = "postgres-only" ) ]
138142 ArrayNull ( NullType ) ,
139143 /// String representation
140144 #[ cfg( feature = "postgres-only" ) ]
141- ArrayString ( & ' a [ & ' a str ] ) ,
145+ ArrayString ( VecCow < ' a , Cow < ' a , str > > ) ,
142146 /// i64 representation
143147 #[ cfg( feature = "postgres-only" ) ]
144- ArrayI64 ( & ' a [ i64 ] ) ,
148+ ArrayI64 ( VecCow < ' a , i64 > ) ,
145149 /// i32 representation
146150 #[ cfg( feature = "postgres-only" ) ]
147- ArrayI32 ( & ' a [ i32 ] ) ,
151+ ArrayI32 ( VecCow < ' a , i32 > ) ,
148152 /// i16 representation
149153 #[ cfg( feature = "postgres-only" ) ]
150- ArrayI16 ( & ' a [ i16 ] ) ,
154+ ArrayI16 ( VecCow < ' a , i16 > ) ,
151155 /// Bool representation
152156 #[ cfg( feature = "postgres-only" ) ]
153- ArrayBool ( & ' a [ bool ] ) ,
157+ ArrayBool ( VecCow < ' a , bool > ) ,
154158 /// f64 representation
155159 #[ cfg( feature = "postgres-only" ) ]
156- ArrayF64 ( & ' a [ f64 ] ) ,
160+ ArrayF64 ( VecCow < ' a , f64 > ) ,
157161 /// f32 representation
158162 #[ cfg( feature = "postgres-only" ) ]
159- ArrayF32 ( & ' a [ f32 ] ) ,
163+ ArrayF32 ( VecCow < ' a , f32 > ) ,
160164 /// binary representation
161165 #[ cfg( feature = "postgres-only" ) ]
162- ArrayBinary ( & ' a [ & ' a [ u8 ] ] ) ,
166+ ArrayBinary ( VecCow < ' a , Cow < ' a , [ u8 ] > > ) ,
163167 /// chrono's Naive Time representation
164168 #[ cfg( feature = "postgres-only" ) ]
165- ArrayChronoNaiveTime ( & ' a [ NaiveTime ] ) ,
169+ ArrayChronoNaiveTime ( VecCow < ' a , NaiveTime > ) ,
166170 /// chrono's Naive Date representation
167171 #[ cfg( feature = "postgres-only" ) ]
168- ArrayChronoNaiveDate ( & ' a [ NaiveDate ] ) ,
172+ ArrayChronoNaiveDate ( VecCow < ' a , NaiveDate > ) ,
169173 /// chrono's Naive DateTime representation
170174 #[ cfg( feature = "postgres-only" ) ]
171- ArrayChronoNaiveDateTime ( & ' a [ NaiveDateTime ] ) ,
175+ ArrayChronoNaiveDateTime ( VecCow < ' a , NaiveDateTime > ) ,
172176 /// chrono's Timezone aware datetime
173177 #[ cfg( feature = "postgres-only" ) ]
174- ArrayChronoDateTime ( & ' a [ DateTime < Utc > ] ) ,
178+ ArrayChronoDateTime ( VecCow < ' a , DateTime < Utc > > ) ,
175179 /// time's date representation
176180 #[ cfg( feature = "postgres-only" ) ]
177- ArrayTimeDate ( & ' a [ Date ] ) ,
181+ ArrayTimeDate ( VecCow < ' a , Date > ) ,
178182 /// time's time representation
179183 #[ cfg( feature = "postgres-only" ) ]
180- ArrayTimeTime ( & ' a [ Time ] ) ,
184+ ArrayTimeTime ( VecCow < ' a , Time > ) ,
181185 /// time's offset datetime representation
182186 #[ cfg( feature = "postgres-only" ) ]
183- ArrayTimeOffsetDateTime ( & ' a [ OffsetDateTime ] ) ,
187+ ArrayTimeOffsetDateTime ( VecCow < ' a , OffsetDateTime > ) ,
184188 /// time's primitive datetime representation
185189 #[ cfg( feature = "postgres-only" ) ]
186- ArrayTimePrimitiveDateTime ( & ' a [ PrimitiveDateTime ] ) ,
190+ ArrayTimePrimitiveDateTime ( VecCow < ' a , PrimitiveDateTime > ) ,
187191 /// Uuid representation
188192 #[ cfg( feature = "postgres-only" ) ]
189- ArrayUuid ( & ' a [ Uuid ] ) ,
193+ ArrayUuid ( VecCow < ' a , Uuid > ) ,
190194 /// serde_json's Value representation
191195 #[ cfg( feature = "postgres-only" ) ]
192- ArrayJsonValue ( & ' a [ & ' a serde_json:: Value ] ) ,
196+ ArrayJsonValue ( VecCow < ' a , & ' a serde_json:: Value > ) ,
193197
194198 /// Mac address representation
195199 #[ cfg( feature = "postgres-only" ) ]
196- ArrayMacAddress ( & ' a [ mac_address:: MacAddress ] ) ,
200+ ArrayMacAddress ( VecCow < ' a , mac_address:: MacAddress > ) ,
197201 /// IP network presentation
198202 #[ cfg( feature = "postgres-only" ) ]
199- ArrayIpNetwork ( & ' a [ ipnetwork:: IpNetwork ] ) ,
203+ ArrayIpNetwork ( VecCow < ' a , ipnetwork:: IpNetwork > ) ,
200204 /// Bit vec representation
201205 #[ cfg( feature = "postgres-only" ) ]
202- ArrayBitVec ( & ' a [ & ' a bit_vec:: BitVec ] ) ,
206+ ArrayBitVec ( VecCow < ' a , Cow < ' a , bit_vec:: BitVec > > ) ,
207+ }
208+
209+ /// [`Value`] should be covariant over `'a`
210+ #[ expect( unused) ]
211+ fn test_variance < ' a , ' b > ( x : Value < ' a > ) -> Value < ' b >
212+ where
213+ ' a : ' b ,
214+ {
215+ x
203216}
0 commit comments