pub trait Item: Sized + Copy {
// Required methods
fn buffer_desc(nullable: bool) -> BufferDesc;
fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>;
fn as_nullable_slice(
variant: AnySlice<'_>,
) -> Option<NullableSlice<'_, Self>>;
fn as_slice_mut(variant: AnySliceMut<'_>) -> Option<&mut [Self]>;
fn as_nullable_slice_mut(
variant: AnySliceMut<'_>,
) -> Option<NullableSliceMut<'_, Self>>;
}Expand description
Can either be extracted as a slice or a NullableSlice from an AnySlice. This allows
the user to avoid matching on all possibile 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::buffer_desc(false), B::buffer_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 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));Sourcefn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>
fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>
Extract the typed nullable buffer from an AnySlice.
Sourcefn as_slice_mut(variant: AnySliceMut<'_>) -> Option<&mut [Self]>
fn as_slice_mut(variant: AnySliceMut<'_>) -> Option<&mut [Self]>
Extract the array type from an AnySliceMut.
Sourcefn as_nullable_slice_mut(
variant: AnySliceMut<'_>,
) -> Option<NullableSliceMut<'_, Self>>
fn as_nullable_slice_mut( variant: AnySliceMut<'_>, ) -> Option<NullableSliceMut<'_, Self>>
Extract the typed nullable buffer from an AnySliceMut.
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.