83
83
}
84
84
85
85
macro_rules! impl_decode_for_smartpointer {
86
- ( $smart_pointer: ty ) => {
87
- impl <' r, DB , T > Decode <' r, DB > for $smart_pointer
86
+ ( $smart_pointer: tt ) => {
87
+ impl <' r, DB , T > Decode <' r, DB > for $smart_pointer< T >
88
88
where
89
89
DB : Database ,
90
90
T : Decode <' r, DB >,
@@ -93,21 +93,66 @@ macro_rules! impl_decode_for_smartpointer {
93
93
Ok ( Self :: new( T :: decode( value) ?) )
94
94
}
95
95
}
96
+
97
+ impl <' r, DB > Decode <' r, DB > for $smart_pointer<str >
98
+ where
99
+ DB : Database ,
100
+ & ' r str : Decode <' r, DB >,
101
+ {
102
+ fn decode( value: <DB as Database >:: ValueRef <' r>) -> Result <Self , BoxDynError > {
103
+ let ref_str = <& str as Decode <DB >>:: decode( value) ?;
104
+ Ok ( ref_str. into( ) )
105
+ }
106
+ }
107
+
108
+ impl <' r, DB > Decode <' r, DB > for $smart_pointer<[ u8 ] >
109
+ where
110
+ DB : Database ,
111
+ & ' r [ u8 ] : Decode <' r, DB >,
112
+ {
113
+ fn decode( value: <DB as Database >:: ValueRef <' r>) -> Result <Self , BoxDynError > {
114
+ let ref_str = <& [ u8 ] as Decode <DB >>:: decode( value) ?;
115
+ Ok ( ref_str. into( ) )
116
+ }
117
+ }
96
118
} ;
97
119
}
98
120
99
- impl_decode_for_smartpointer ! ( Arc < T > ) ;
100
- impl_decode_for_smartpointer ! ( Box < T > ) ;
101
- impl_decode_for_smartpointer ! ( Rc < T > ) ;
121
+ impl_decode_for_smartpointer ! ( Arc ) ;
122
+ impl_decode_for_smartpointer ! ( Box ) ;
123
+ impl_decode_for_smartpointer ! ( Rc ) ;
102
124
103
125
// implement `Decode` for Cow<T> for all SQL types
104
126
impl < ' r , DB , T > Decode < ' r , DB > for Cow < ' _ , T >
105
127
where
106
128
DB : Database ,
107
- T : Decode < ' r , DB > ,
108
- T : ToOwned < Owned = T > ,
129
+ T : ToOwned ,
130
+ <T as ToOwned >:: Owned : Decode < ' r , DB > ,
131
+ {
132
+ fn decode ( value : <DB as Database >:: ValueRef < ' r > ) -> Result < Self , BoxDynError > {
133
+ let owned = <<T as ToOwned >:: Owned as Decode < DB > >:: decode ( value) ?;
134
+ Ok ( Cow :: Owned ( owned) )
135
+ }
136
+ }
137
+
138
+ impl < ' r , DB > Decode < ' r , DB > for Cow < ' r , str >
139
+ where
140
+ DB : Database ,
141
+ & ' r str : Decode < ' r , DB > ,
142
+ {
143
+ fn decode ( value : <DB as Database >:: ValueRef < ' r > ) -> Result < Self , BoxDynError > {
144
+ let borrowed = <& str as Decode < DB > >:: decode ( value) ?;
145
+ Ok ( Cow :: Borrowed ( borrowed) )
146
+ }
147
+ }
148
+
149
+ impl < ' r , DB > Decode < ' r , DB > for Cow < ' r , [ u8 ] >
150
+ where
151
+ DB : Database ,
152
+ & ' r [ u8 ] : Decode < ' r , DB > ,
109
153
{
110
154
fn decode ( value : <DB as Database >:: ValueRef < ' r > ) -> Result < Self , BoxDynError > {
111
- Ok ( Cow :: Owned ( T :: decode ( value) ?) )
155
+ let borrowed = <& [ u8 ] as Decode < DB > >:: decode ( value) ?;
156
+ Ok ( Cow :: Borrowed ( borrowed) )
112
157
}
113
158
}
0 commit comments