Trait odbc_api::buffers::Item

source ·
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§

source

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));
source

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

Extract the array type from an AnySlice.

source

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

Extract the typed nullable buffer from an AnySlice.

source

fn as_slice_mut(variant: AnySliceMut<'_>) -> Option<&mut [Self]>

Extract the array type from an AnySliceMut.

source

fn as_nullable_slice_mut( variant: AnySliceMut<'_> ) -> Option<NullableSliceMut<'_, Self>>

Extract the typed nullable buffer from an AnySliceMut.

Implementations on Foreign Types§

source§

impl Item for i64

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

source§

impl Item for Date

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

source§

impl Item for i32

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

source§

impl Item for i16

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

source§

impl Item for u8

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

source§

impl Item for Timestamp

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

source§

impl Item for f32

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

source§

impl Item for f64

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

source§

impl Item for Time

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

source§

impl Item for i8

source§

fn buffer_desc(nullable: bool) -> BufferDesc

source§

fn as_slice(variant: AnySlice<'_>) -> Option<&[Self]>

source§

fn as_nullable_slice(variant: AnySlice<'_>) -> Option<NullableSlice<'_, Self>>

source§

fn as_slice_mut<'a>(variant: AnySliceMut<'a>) -> Option<&'a mut [Self]>

source§

fn as_nullable_slice_mut<'a>( variant: AnySliceMut<'a> ) -> Option<NullableSliceMut<'a, Self>>

Implementors§

source§

impl Item for Bit