Trait xitca_postgres::FromSqlExt

source ·
pub trait FromSqlExt<'a>: Sized {
    // Required methods
    fn from_sql_nullable_ext(
        ty: &Type,
        col: (&Range<usize>, &'a Bytes),
    ) -> Result<Self, Box<dyn Error + Sync + Send>>;
    fn accepts(ty: &Type) -> bool;
}
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_nullable_ext( ty: &Type, col: (&Range<usize>, &'a Bytes), ) -> Result<Self, Box<dyn Error + Sync + Send>>

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. When Range is an empty value it indicates trait implementor encounters a null pg value. It’s suggested to call Range::is_empty to check for this case and properly handle it

source

fn accepts(ty: &Type) -> bool

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a> FromSqlExt<'a> for &'a str

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for &'a [u8]

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for bool

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for f32

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for f64

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for i8

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for i16

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for i32

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for i64

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for u32

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for Box<str>

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a> FromSqlExt<'a> for String

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

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

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

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

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

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

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a, T> FromSqlExt<'a> for Box<[T]>
where T: FromSql<'a>,

source§

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

source§

fn accepts(ty: &Type) -> bool

source§

impl<'a, T> FromSqlExt<'a> for Vec<T>
where T: FromSql<'a>,

source§

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

source§

fn accepts(ty: &Type) -> bool

Implementors§