@@ -593,21 +593,12 @@ impl error::Error for WasNull {
593
593
/// `Option<T>` where `T` implements `FromSql`. An `Option<T>` represents a
594
594
/// nullable Postgres value.
595
595
pub trait FromSql : Sized {
596
- /// Creates a new value of this type from a `Read`er of Postgres data.
597
- ///
598
- /// If the value was `NULL`, the `Read`er will be `None`.
599
- ///
600
- /// The caller of this method is responsible for ensuring that this type
601
- /// is compatible with the Postgres `Type`.
602
- ///
603
- /// The default implementation calls `FromSql::from_sql` when `raw` is
604
- /// `Some` and returns `Err(Error::Conversion(Box::new(WasNull))` when
605
- /// `raw` is `None`. It does not typically need to be overridden.
596
+ /// ### Deprecated
606
597
fn from_sql_nullable < R : Read > ( ty : & Type , raw : Option < & mut R > , ctx : & SessionInfo )
607
598
-> Result < Self > {
608
599
match raw {
609
600
Some ( raw) => FromSql :: from_sql ( ty, raw, ctx) ,
610
- None => Err ( Error :: Conversion ( Box :: new ( WasNull ) ) ) ,
601
+ None => FromSql :: from_sql_null ( ty , ctx ) ,
611
602
}
612
603
}
613
604
@@ -618,24 +609,31 @@ pub trait FromSql: Sized {
618
609
/// is compatible with the Postgres `Type`.
619
610
fn from_sql < R : Read > ( ty : & Type , raw : & mut R , ctx : & SessionInfo ) -> Result < Self > ;
620
611
612
+ /// Creates a new value of this type from a `NULL` SQL value.
613
+ ///
614
+ /// The caller of this method is responsible for ensuring that this type
615
+ /// is compatible with the Postgres `Type`.
616
+ ///
617
+ /// The default implementation returns
618
+ /// `Err(Error::Conversion(Box::new(WasNull))`.
619
+ fn from_sql_null ( ty : & Type , ctx : & SessionInfo ) -> Result < Self > {
620
+ Err ( Error :: Conversion ( Box :: new ( WasNull ) ) )
621
+ }
622
+
621
623
/// Determines if a value of this type can be created from the specified
622
624
/// Postgres `Type`.
623
625
fn accepts ( ty : & Type ) -> bool ;
624
626
}
625
627
626
628
impl < T : FromSql > FromSql for Option < T > {
627
- fn from_sql_nullable < R : Read > ( ty : & Type , raw : Option < & mut R > , ctx : & SessionInfo )
628
- -> Result < Option < T > > {
629
- match raw {
630
- Some ( raw) => <T as FromSql >:: from_sql ( ty, raw, ctx) . map ( Some ) ,
631
- None => Ok ( None ) ,
632
- }
633
- }
634
-
635
629
fn from_sql < R : Read > ( ty : & Type , raw : & mut R , ctx : & SessionInfo ) -> Result < Option < T > > {
636
630
<T as FromSql >:: from_sql ( ty, raw, ctx) . map ( Some )
637
631
}
638
632
633
+ fn from_sql_null ( _: & Type , _: & SessionInfo ) -> Result < Option < T > > {
634
+ Ok ( None )
635
+ }
636
+
639
637
fn accepts ( ty : & Type ) -> bool {
640
638
<T as FromSql >:: accepts ( ty)
641
639
}
0 commit comments