Struct odbc_api::buffers::BinColumnWriter[][src]

pub struct BinColumnWriter<'a> { /* fields omitted */ }

Fills a binary column buffer with elements from an Iterator. See crate::buffers::AnyColumnViewMut

Implementations

impl<'a> BinColumnWriter<'a>[src]

pub fn write<'b>(&mut self, it: impl Iterator<Item = Option<&'b [u8]>>)[src]

Fill the binary column with values by consuming the iterator and copying its items into the buffer. It will not extract more items from the iterator than the buffer may hold. This method panics if elements of the iterator are larger than the maximum element length of the buffer.

pub fn set_max_len(&mut self, new_max_len: usize)[src]

Changes the maximum element length the buffer can hold. This operation is useful if you find an unexpected large input during insertion. All values in the buffer will be set to NULL.

Parameters

  • new_max_len: New maximum element length

pub fn max_len(&self) -> usize[src]

Maximum length

pub fn rebind(&mut self, new_max_len: usize, num_rows: usize)[src]

Changes the maximum element length the buffer can hold. This operation is useful if you find an unexpected large input during insertion.

This is however costly, as not only does the new buffer have to be allocated, but all values have to copied from the old to the new buffer.

This method could also be used to reduce the maximum element length, which would truncate values in the process.

This method does not adjust indicator buffers as these might hold values larger than the maximum element length.

Parameters

  • new_max_len: New maximum element length.
  • num_rows: Number of valid rows currently stored in this buffer.

pub fn append(&mut self, index: usize, bytes: Option<&[u8]>)[src]

Inserts a new element to the column buffer. Rebinds the buffer to increase maximum element length should the value be larger than the maximum allowed element length. The number of rows the column buffer can hold stays constant, but during rebind only values before index would be copied to the new memory location. Therefore this method is intended to be used to fill the buffer element-wise and in order. Hence the name append.

Parameters

  • index: Zero based index of the new row position. Must be equal to the number of rows currently in the buffer.
  • bytes: Value to store

Example

    ColumnarRowSet, BufferDescription, BufferKind, AnyColumnViewMut, AnyColumnView
};
let desc = BufferDescription {
    // Buffer size purposefully chosen too small, so we need to increase the buffer size if we
    // encounter larger inputs.
    kind: BufferKind::Binary { length: 1 },
    nullable: true,
};

// Input values to insert.
let input : [Option<&[u8]>; 5]= [
    Some(&[1]),
    Some(&[2,3]),
    Some(&[4,5,6]),
    None,
    Some(&[7,8,9,10,11,12]),
];

let mut buffer = ColumnarRowSet::new(input.len() as u32, iter::once(desc));

buffer.set_num_rows(input.len());
if let AnyColumnViewMut::Binary(mut writer) = buffer.column_mut(0) {
    for (index, &bytes) in input.iter().enumerate() {
        writer.append(index, bytes)
    }
} else {
    panic!("Expected binary column writer");
}

if let AnyColumnView::Binary(col) = buffer.column(0) {
    assert!(col.zip(input.iter().copied()).all(|(expected, actual)| expected == actual))
} else {
    panic!("Expected binary column slice");   
}

Trait Implementations

impl<'a> Debug for BinColumnWriter<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for BinColumnWriter<'a>

impl<'a> Send for BinColumnWriter<'a>

impl<'a> Sync for BinColumnWriter<'a>

impl<'a> Unpin for BinColumnWriter<'a>

impl<'a> !UnwindSafe for BinColumnWriter<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.