@@ -452,10 +452,11 @@ impl WrongType {
452
452
///
453
453
/// # Arrays
454
454
///
455
- /// `FromSql` is implemented for `Vec<T>` and `[T; N]` where `T` implements
456
- /// `FromSql`, and corresponds to one-dimensional Postgres arrays. **Note:**
457
- /// the impl for arrays only exist when the Cargo feature `array-impls` is
458
- /// enabled.
455
+ /// `FromSql` is implemented for `Vec<T>`, `Box<[T]>` and `[T; N]` where `T`
456
+ /// implements `FromSql`, and corresponds to one-dimensional Postgres arrays.
457
+ ///
458
+ /// **Note:** the impl for arrays only exist when the Cargo feature `array-impls`
459
+ /// is enabled.
459
460
pub trait FromSql < ' a > : Sized {
460
461
/// Creates a new value of this type from a buffer of data of the specified
461
462
/// Postgres `Type` in its binary format.
@@ -580,6 +581,16 @@ impl<'a, T: FromSql<'a>, const N: usize> FromSql<'a> for [T; N] {
580
581
}
581
582
}
582
583
584
+ impl < ' a , T : FromSql < ' a > > FromSql < ' a > for Box < [ T ] > {
585
+ fn from_sql ( ty : & Type , raw : & ' a [ u8 ] ) -> Result < Self , Box < dyn Error + Sync + Send > > {
586
+ Vec :: < T > :: from_sql ( ty, raw) . map ( Vec :: into_boxed_slice)
587
+ }
588
+
589
+ fn accepts ( ty : & Type ) -> bool {
590
+ Vec :: < T > :: accepts ( ty)
591
+ }
592
+ }
593
+
583
594
impl < ' a > FromSql < ' a > for Vec < u8 > {
584
595
fn from_sql ( _: & Type , raw : & ' a [ u8 ] ) -> Result < Vec < u8 > , Box < dyn Error + Sync + Send > > {
585
596
Ok ( types:: bytea_from_sql ( raw) . to_owned ( ) )
@@ -783,10 +794,12 @@ pub enum IsNull {
783
794
///
784
795
/// # Arrays
785
796
///
786
- /// `ToSql` is implemented for `Vec<T>`, `&[T]` and `[T; N]` where `T`
787
- /// implements `ToSql`, and corresponds to one-dimensional Postgres arrays with
788
- /// an index offset of 1. **Note:** the impl for arrays only exist when the
789
- /// Cargo feature `array-impls` is enabled.
797
+ /// `ToSql` is implemented for `Vec<T>`, `&[T]`, `Box<[T]>` and `[T; N]` where
798
+ /// `T` implements `ToSql`, and corresponds to one-dimensional Postgres arrays
799
+ /// with an index offset of 1.
800
+ ///
801
+ /// **Note:** the impl for arrays only exist when the Cargo feature `array-impls`
802
+ /// is enabled.
790
803
pub trait ToSql : fmt:: Debug {
791
804
/// Converts the value of `self` into the binary format of the specified
792
805
/// Postgres `Type`, appending it to `out`.
@@ -927,6 +940,18 @@ impl<T: ToSql> ToSql for Vec<T> {
927
940
to_sql_checked ! ( ) ;
928
941
}
929
942
943
+ impl < T : ToSql > ToSql for Box < [ T ] > {
944
+ fn to_sql ( & self , ty : & Type , w : & mut BytesMut ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
945
+ <& [ T ] as ToSql >:: to_sql ( & & * * self , ty, w)
946
+ }
947
+
948
+ fn accepts ( ty : & Type ) -> bool {
949
+ <& [ T ] as ToSql >:: accepts ( ty)
950
+ }
951
+
952
+ to_sql_checked ! ( ) ;
953
+ }
954
+
930
955
impl ToSql for Vec < u8 > {
931
956
fn to_sql ( & self , ty : & Type , w : & mut BytesMut ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
932
957
<& [ u8 ] as ToSql >:: to_sql ( & & * * self , ty, w)
0 commit comments