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§
Sourcefn from_sql_nullable_ext(
ty: &Type,
col: (&Range<usize>, &'a Bytes),
) -> 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>>
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
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.