pub trait Item: Pod {
// Required methods
fn bind_param_desc(nullable: bool) -> BindParamDesc;
fn buffer_desc(nullable: bool) -> BufferDesc;
}Expand description
Can either be extracted as a slice or a [NullableSlice] from an [AnySlice]. This allows
the user to avoid matching on all possible variants of an [AnySlice] in case the
buffered type is known at compile time.
Usually used in generic code. E.g.:
use odbc_api::{Connection, buffers::Item};
fn insert_tuple2_vec<A: Item, B: Item>(
conn: &Connection<'_>,
insert_sql: &str,
source: &[(A, B)],
) {
let mut prepared = conn.prepare(insert_sql).unwrap();
// Number of rows submitted in one round trip
let capacity = source.len();
// We do not need a nullable buffer since elements of source are not optional
let descriptions = [A::bind_param_desc(false), B::bind_param_desc(false)];
let mut inserter = prepared.column_inserter(capacity, descriptions).unwrap();
// We send everything in one go.
inserter.set_num_rows(source.len());
// Now let's copy the row based tuple into the columnar structure
for (index, (a, b)) in source.iter().enumerate() {
inserter.column_mut(0).as_slice::<A>().unwrap()[index] = *a;
inserter.column_mut(1).as_slice::<B>().unwrap()[index] = *b;
}
inserter.execute().unwrap();
}Required Methods§
Sourcefn bind_param_desc(nullable: bool) -> BindParamDesc
fn bind_param_desc(nullable: bool) -> BindParamDesc
Useful to instantiate a crate::ColumnarBulkInserter in generic code.
Sourcefn buffer_desc(nullable: bool) -> BufferDesc
fn buffer_desc(nullable: bool) -> BufferDesc
Can be used to instantiate a super::ColumnarBuffer. This is useful to allocate the
correct buffers in generic code.
§Example:
Specification:
use odbc_api::buffers::{Item, BufferDesc};
assert_eq!(BufferDesc::I64{ nullable: true }, i64::buffer_desc(true));
assert_eq!(BufferDesc::I64{ nullable: false }, i64::buffer_desc(false));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".