use crate::{PropValue, sys};
use core::{mem, slice};
use std::ptr;
pub struct Row {
count: usize,
props: *mut sys::SPropValue,
}
impl Row {
pub fn new(row: &mut sys::SRow) -> Self {
Self {
count: mem::replace(&mut row.cValues, 0) as usize,
props: mem::replace(&mut row.lpProps, ptr::null_mut()),
}
}
pub fn is_empty(&self) -> bool {
self.count == 0 || self.props.is_null()
}
pub fn len(&self) -> usize {
if self.props.is_null() { 0 } else { self.count }
}
pub fn iter(&self) -> impl Iterator<Item = PropValue<'_>> {
if self.props.is_null() {
vec![]
} else {
unsafe {
let data: &[sys::SPropValue] = slice::from_raw_parts(self.props, self.count);
data.iter().map(PropValue::from).collect()
}
}
.into_iter()
}
}
impl Drop for Row {
fn drop(&mut self) {
if !self.props.is_null() {
unsafe {
sys::MAPIFreeBuffer(self.props as *mut _);
}
}
}
}