use crate::{sys, PropValue};
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);
let data = data.iter().map(PropValue::from).collect();
data
}
}
.into_iter()
}
}
impl Drop for Row {
fn drop(&mut self) {
if !self.props.is_null() {
unsafe {
sys::MAPIFreeBuffer(mem::transmute(self.props));
}
}
}
}