1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use vortex_dtype::DType;
use vortex_error::{vortex_bail, VortexResult};

use super::projections::Projection;

#[derive(Clone, Debug)]
pub struct Schema(pub(crate) DType);

impl Schema {
    pub fn project(&self, projection: Projection) -> VortexResult<Self> {
        match projection {
            Projection::All => Ok(self.clone()),
            Projection::Flat(indices) => {
                let DType::Struct(s, n) = &self.0 else {
                    vortex_bail!("Can't project non struct types")
                };
                s.project(indices.as_ref())
                    .map(|p| Self(DType::Struct(p, *n)))
            }
        }
    }

    pub fn dtype(&self) -> &DType {
        &self.0
    }

    pub fn into_dtype(self) -> DType {
        self.0
    }
}