pub unsafe fn read_duck_string<'a>(data: *const u8, idx: usize) -> &'a strExpand description
Reads a DuckDB VARCHAR value from a raw vector data pointer at a given row index.
Returns the string as a &str slice, or an empty string if the data is not
valid UTF-8 or if the pointer is null.
§Pitfall P7
DuckDB strings have two storage formats:
- Inline (≤ 12 bytes): stored directly in the 16-byte struct
- Pointer (> 12 bytes): struct contains a pointer to heap-allocated data
This function handles both transparently.
§Safety
datamust point to aDuckDBVARCHAR vector’s data buffer.idxmust be within bounds of the vector.- For pointer-format strings, the heap data pointed to must be valid for the
duration of this function call and the returned
&strslice. - The returned
&strborrows from theDuckDBvector — do not destroy the data chunk while the returned reference is live.
§Example
use quack_rs::vector::string::read_duck_string;
// Inside a DuckDB aggregate callback:
// let data = libduckdb_sys::duckdb_vector_get_data(vec) as *const u8;
// let s = unsafe { read_duck_string(data, row_idx) };