Struct odbc_api::buffers::BinColumnWriter
source · [−]pub struct BinColumnWriter<'a> { /* private fields */ }
Expand description
Fills a binary column buffer with elements from an Iterator. See
crate::buffers::AnyColumnViewMut
Implementations
sourceimpl<'a> BinColumnWriter<'a>
impl<'a> BinColumnWriter<'a>
sourcepub fn write<'b>(&mut self, it: impl Iterator<Item = Option<&'b [u8]>>)
pub fn write<'b>(&mut self, it: impl Iterator<Item = Option<&'b [u8]>>)
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.
sourcepub fn set_max_len(&mut self, new_max_len: usize)
pub fn set_max_len(&mut self, new_max_len: usize)
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
sourcepub fn resize_max_element_length(&mut self, new_max_len: usize, num_rows: usize)
pub fn resize_max_element_length(&mut self, new_max_len: usize, num_rows: usize)
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.
sourcepub fn append(&mut self, index: usize, bytes: Option<&[u8]>)
pub fn append(&mut self, index: usize, bytes: Option<&[u8]>)
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
BufferDescription, BufferKind, AnyColumnViewMut, AnyColumnView, buffer_from_description
};
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 = buffer_from_description(input.len(), 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");
}
let col_view = buffer.column(0).as_bin_view().expect("Expected binary column slice");
assert!(
col_view
.iter()
.zip(input.iter().copied())
.all(|(expected, actual)| expected == actual)
)
Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more