FromSqlExt

Trait FromSqlExt 

Source
pub trait FromSqlExt<'a>: Sized {
    // Required methods
    fn from_sql_ext(
        ty: &Type,
        col: (&Range<usize>, &'a Bytes),
    ) -> Result<Self, Box<dyn Error + Sync + Send>>;
    fn accepts_ext(ty: &Type) -> bool;

    // Provided methods
    fn from_sql_null_ext(
        ty: &Type,
    ) -> Result<Self, Box<dyn Error + Sync + Send>> { ... }
    fn from_sql_nullable_ext(
        ty: &Type,
        col: (&Range<usize>, &'a Bytes),
    ) -> Result<Self, Box<dyn Error + Sync + Send>> { ... }
}
Expand description

extension trait for FromSql

instead of working with explicit reference as &[u8] for parsing raw sql bytes this extension offers cheap copy/slicing of Bytes type for reference counting based zero copy parsing.

§Examples

use xitca_unsafe_collection::bytes::BytesStr; // a reference counted &str type has FromSqlExt impl
fn parse_row(row: Row<'_>) {
    let s = row.get_zc::<BytesStr>(0); // parse index0 column with zero copy.
    println!("{}", s.as_str());
}

Required Methods§

Source

fn from_sql_ext( ty: &Type, col: (&Range<usize>, &'a Bytes), ) -> Result<Self, Box<dyn Error + Sync + Send>>

byte parser of non null Postgres type Type represents the Postgres type hint which Self must be matching. Bytes represents the reference of raw bytes of row data Self belongs to. Range represents the start and end indexing into the raw data for correctly parsing Self.

Source

fn accepts_ext(ty: &Type) -> bool

Determines if a value of this type can be created from the specified Postgres Type.

Provided Methods§

Source

fn from_sql_null_ext(ty: &Type) -> Result<Self, Box<dyn Error + Sync + Send>>

Creates a new value of this type from a NULL SQL value.

The caller of this method is responsible for ensuring that this type is compatible with the Postgres Type.

The default implementation returns Err(Box::new(WasNull)).

Source

fn from_sql_nullable_ext( ty: &Type, col: (&Range<usize>, &'a Bytes), ) -> Result<Self, Box<dyn Error + Sync + Send>>

A convenience function that delegates to from_sql and from_sql_null.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a> FromSqlExt<'a> for Bytes

Source§

fn from_sql_ext( _: &Type, (range, buf): (&Range<usize>, &'a Bytes), ) -> Result<Self, Box<dyn Error + Sync + Send>>

Source§

fn accepts_ext(ty: &Type) -> bool

Source§

impl<'a> FromSqlExt<'a> for BytesStr

Source§

fn from_sql_ext( ty: &Type, (range, buf): (&Range<usize>, &'a Bytes), ) -> Result<Self, Box<dyn Error + Sync + Send>>

Source§

fn accepts_ext(ty: &Type) -> bool

Source§

impl<'a, T> FromSqlExt<'a> for Option<T>
where T: FromSqlExt<'a>,

Source§

fn from_sql_ext( ty: &Type, raw: (&Range<usize>, &'a Bytes), ) -> Result<Option<T>, Box<dyn Error + Sync + Send>>

Source§

fn from_sql_null_ext( _: &Type, ) -> Result<Option<T>, Box<dyn Error + Sync + Send>>

Source§

fn accepts_ext(ty: &Type) -> bool

Implementors§