vortex_layout/
strategy.rs1use vortex_array::ArrayContext;
7use vortex_dtype::DType;
8use vortex_error::VortexResult;
9
10use crate::layouts::flat::writer::FlatLayoutWriter;
11use crate::layouts::struct_::writer::StructLayoutWriter;
12use crate::writer::{LayoutWriter, LayoutWriterExt};
13
14pub trait LayoutStrategy: 'static + Send + Sync {
16 fn new_writer(&self, ctx: &ArrayContext, dtype: &DType) -> VortexResult<Box<dyn LayoutWriter>>;
17}
18
19pub struct StructStrategy;
21
22impl LayoutStrategy for StructStrategy {
23 fn new_writer(&self, ctx: &ArrayContext, dtype: &DType) -> VortexResult<Box<dyn LayoutWriter>> {
24 if let DType::Struct(..) = dtype {
25 StructLayoutWriter::try_new_with_strategy(ctx, dtype, StructStrategy).map(|w| w.boxed())
26 } else {
27 Ok(FlatLayoutWriter::new(ctx.clone(), dtype.clone(), Default::default()).boxed())
28 }
29 }
30}