pub struct Row { /* private fields */ }Expand description
A row from a query result.
Implements the Arc<Bytes> pattern from ADR-004 for reduced memory allocation.
The row holds a shared reference to the raw packet buffer and column slice
information, deferring parsing and allocation until values are accessed.
§Memory Model
Row {
buffer: Arc<Bytes> ──────────► [raw packet data...]
slices: Arc<[ColumnSlice]> ──► [{offset, length, is_null}, ...]
metadata: Arc<ColMetaData> ──► [Column definitions...]
}Multiple Row instances from the same result set share the metadata.
The buffer and slices are unique per row but use Arc for cheap cloning.
§Access Patterns
- Zero-copy:
get_bytes(),get_str()(when UTF-8 valid) - Allocating:
get_string(),get::<String>() - Type-converting:
get::<T>()usesFromSqltrait
Implementations§
Source§impl Row
impl Row
Sourcepub fn new(
buffer: Arc<Bytes>,
slices: Arc<[ColumnSlice]>,
metadata: Arc<ColMetaData>,
) -> Self
pub fn new( buffer: Arc<Bytes>, slices: Arc<[ColumnSlice]>, metadata: Arc<ColMetaData>, ) -> Self
Create a new row with the Arc<Bytes> pattern.
This is the primary constructor for the reduced-copy pattern.
Sourcepub fn get_bytes(&self, index: usize) -> Option<&[u8]>
pub fn get_bytes(&self, index: usize) -> Option<&[u8]>
Returns borrowed slice into buffer (zero additional allocation).
This is the most efficient access method when you need raw bytes.
Sourcepub fn get_str(&self, index: usize) -> Option<Cow<'_, str>>
pub fn get_str(&self, index: usize) -> Option<Cow<'_, str>>
Returns Cow - borrowed if valid UTF-8, owned if conversion needed.
For UTF-8 data, this returns a borrowed reference (zero allocation). For UTF-16 data (NVARCHAR), this allocates a new String.
Sourcepub fn get_string(&self, index: usize) -> Option<String>
pub fn get_string(&self, index: usize) -> Option<String>
Allocates new String (explicit allocation).
Use this when you need an owned String.
Sourcepub fn get<T: FromSql>(&self, index: usize) -> Result<T, TypeError>
pub fn get<T: FromSql>(&self, index: usize) -> Result<T, TypeError>
Get a value by column index with type conversion.
Uses the FromSql trait to convert the raw value to the requested type.
Sourcepub fn get_by_name<T: FromSql>(&self, name: &str) -> Result<T, TypeError>
pub fn get_by_name<T: FromSql>(&self, name: &str) -> Result<T, TypeError>
Get a value by column name with type conversion.
Sourcepub fn try_get<T: FromSql>(&self, index: usize) -> Option<T>
pub fn try_get<T: FromSql>(&self, index: usize) -> Option<T>
Try to get a value by column index, returning None if NULL or not found.
Sourcepub fn try_get_by_name<T: FromSql>(&self, name: &str) -> Option<T>
pub fn try_get_by_name<T: FromSql>(&self, name: &str) -> Option<T>
Try to get a value by column name, returning None if NULL or not found.
Sourcepub fn get_raw(&self, index: usize) -> Option<SqlValue>
pub fn get_raw(&self, index: usize) -> Option<SqlValue>
Get the raw SQL value by index.
Note: This may allocate if values haven’t been cached.
Sourcepub fn get_raw_by_name(&self, name: &str) -> Option<SqlValue>
pub fn get_raw_by_name(&self, name: &str) -> Option<SqlValue>
Get the raw SQL value by column name.
Sourcepub fn metadata(&self) -> &Arc<ColMetaData>
pub fn metadata(&self) -> &Arc<ColMetaData>
Get the shared column metadata.
Sourcepub fn is_null_by_name(&self, name: &str) -> bool
pub fn is_null_by_name(&self, name: &str) -> bool
Check if a column value is NULL by name.