odbc_api::buffers

Struct NullableSliceMut

Source
pub struct NullableSliceMut<'a, T> { /* private fields */ }
Expand description

Used to fill a column buffer with an iterator. Returned by crate::ColumnarBulkInserter::column_mut as part of an crate::buffers::AnySliceMut.

Implementations§

Source§

impl<'a, T> NullableSliceMut<'a, T>

Source

pub fn is_empty(&self) -> bool

true if the slice has a length of 0.

Source

pub fn len(&self) -> usize

Number of entries in this slice of the buffer

Source

pub fn set_cell(&mut self, index: usize, cell: Option<T>)

Sets the value at the specified index. Use None to specify a NULL value.

Source

pub fn raw_values(&mut self) -> (&mut [T], &mut [isize])

Write access to the underlying raw value and indicator buffer.

The number of elements in the buffer is equal to len.

This method is useful for writing performant bindings to datastructures with similar binary layout, as it allows for using memcopy rather than iterating over individual values.

§Example
use odbc_api::{buffers::NullableSliceMut, sys::NULL_DATA};

// Memcopy the values into the buffer, and set indicators according to mask
// values.
fn copy_values_and_make_mask(
    new_values: &[i32],
    mask: &[bool],
    odbc_slice: &mut NullableSliceMut<i32>)
{
    let (values, indicators) = odbc_slice.raw_values();
    values.copy_from_slice(new_values);
    // Create array of bools indicating null values.
    indicators.iter_mut().zip(mask.iter()).for_each(|(indicator, &mask)| {
        *indicator = if mask {
            0
        } else {
            NULL_DATA
        }
    });
}
Source§

impl<'a, T> NullableSliceMut<'a, T>

Source

pub fn write(&mut self, it: impl Iterator<Item = Option<T>>)

Writes the elements returned by the iterator into the buffer, starting at the beginning. Writes elements until the iterator returns None or the buffer can not hold more elements.

Trait Implementations§

Source§

impl<'a, T: Debug> Debug for NullableSliceMut<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for NullableSliceMut<'a, T>

§

impl<'a, T> RefUnwindSafe for NullableSliceMut<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for NullableSliceMut<'a, T>
where T: Send,

§

impl<'a, T> Sync for NullableSliceMut<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for NullableSliceMut<'a, T>

§

impl<'a, T> !UnwindSafe for NullableSliceMut<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.