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§
Sourcefn from_sql_ext(
ty: &Type,
col: (&Range<usize>, &'a Bytes),
) -> Result<Self, Box<dyn Error + Sync + Send>>
fn from_sql_ext( ty: &Type, col: (&Range<usize>, &'a Bytes), ) -> Result<Self, Box<dyn Error + Sync + Send>>
Sourcefn accepts_ext(ty: &Type) -> bool
fn accepts_ext(ty: &Type) -> bool
Determines if a value of this type can be created from the specified Postgres Type.
Provided Methods§
Sourcefn from_sql_null_ext(ty: &Type) -> Result<Self, Box<dyn Error + Sync + Send>>
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)).
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.