use std::any::Any;
use std::any::TypeId;
use std::fmt;
use std::sync::Arc;
#[derive(Clone, Default)]
pub struct ArrowExportOptions {
values: Vec<(TypeId, Arc<dyn Any + Send + Sync>)>,
}
impl ArrowExportOptions {
pub fn with<T: Any + Send + Sync>(mut self, option: T) -> Self {
let id = TypeId::of::<T>();
if let Some((_, value)) = self.values.iter_mut().find(|(key, _)| *key == id) {
*value = Arc::new(option);
} else {
self.values.push((id, Arc::new(option)));
}
self
}
pub fn get<T: Any + Send + Sync>(&self) -> Option<&T> {
self.values
.iter()
.find(|(key, _)| *key == TypeId::of::<T>())
.and_then(|(_, value)| value.downcast_ref())
}
pub fn get_or_default<T: Any + Send + Sync + Clone + Default>(&self) -> T {
self.get::<T>().cloned().unwrap_or_default()
}
}
impl fmt::Debug for ArrowExportOptions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ArrowExportOptions")
.field("option_count", &self.values.len())
.finish_non_exhaustive()
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct CompactBuffers(pub bool);
impl Default for CompactBuffers {
fn default() -> Self {
Self(true)
}
}
#[cfg(test)]
mod tests;