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
31
32
33
34
35
36
37
38
39
40
41
use crate::ModelFormat;
use chemrust_core::data::lattice::BasicLatticeModel;
use std::{io, marker::PhantomData, path::Path};

mod cell;
mod msi;

pub use cell::Cell;
pub use msi::Msi;

#[derive(Debug, Clone)]
pub struct StructureFile<T: ModelFormat> {
    lattice_model: BasicLatticeModel,
    format: PhantomData<T>,
}

impl<T: ModelFormat> StructureFile<T> {
    pub fn new(lattice_model: BasicLatticeModel) -> Self {
        Self {
            lattice_model,
            format: PhantomData,
        }
    }

    pub fn lattice_model(&self) -> &BasicLatticeModel {
        &self.lattice_model
    }
}

pub trait FileExport {
    fn write_to<P: AsRef<Path>>(&self, path: &P) -> Result<(), io::Error>;
}

impl<T: ModelFormat> From<BasicLatticeModel> for StructureFile<T> {
    fn from(value: BasicLatticeModel) -> Self {
        Self {
            lattice_model: value,
            format: PhantomData,
        }
    }
}