conspire/geometry/grid/write/
mod.rs1mod spn;
2mod vti;
3
4use crate::{
5 geometry::grid::Grid,
6 io::{Npy, NpyType, Write},
7};
8use std::{fmt::Display, io::Error as ErrorIO, path::Path};
9
10pub enum Output<P>
11where
12 P: AsRef<Path>,
13{
14 Npy(P),
15 Spn(P),
16 Vti(P),
17}
18
19impl<P> AsRef<Path> for Output<P>
20where
21 P: AsRef<Path>,
22{
23 fn as_ref(&self) -> &Path {
24 match self {
25 Output::Npy(path) => path.as_ref(),
26 Output::Spn(path) => path.as_ref(),
27 Output::Vti(path) => path.as_ref(),
28 }
29 }
30}
31
32impl<const D: usize, T, P> Write<Output<P>> for Grid<D, T>
33where
34 P: AsRef<Path>,
35 T: NpyType + Display,
36{
37 type Error = ErrorIO;
38 fn write(&self, output: Output<P>) -> Result<(), Self::Error> {
39 match output {
40 Output::Npy(path) => Npy {
41 data: self.data().to_vec(),
42 shape: self.nel().to_vec(),
43 fortran_order: self.is_col_major(),
44 }
45 .write(path)?,
46 Output::Spn(path) => spn::write(self, path)?,
47 Output::Vti(path) => vti::write(self, path)?,
48 }
49 Ok(())
50 }
51}