module_util/file/
format.rs1use std::fmt;
2use std::path::{Path, PathBuf};
3
4use module::Error;
5use serde::Deserialize;
6use serde::de::DeserializeOwned;
7
8#[derive(Default, Clone, Deserialize)]
12pub struct Imports(pub(crate) Vec<PathBuf>);
13
14impl fmt::Debug for Imports {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 self.0.fmt(f)
17 }
18}
19
20impl From<Vec<PathBuf>> for Imports {
21 fn from(value: Vec<PathBuf>) -> Self {
22 Self(value)
23 }
24}
25
26impl<A> FromIterator<A> for Imports
27where
28 A: Into<PathBuf>,
29{
30 fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
31 Self(iter.into_iter().map(Into::into).collect())
32 }
33}
34
35#[derive(Debug, Default, Clone, Deserialize)]
39pub struct Module<T> {
40 #[serde(default)]
48 pub imports: Imports,
49
50 #[serde(flatten)]
52 pub value: T,
53}
54
55pub trait Format {
62 fn read<T>(&mut self, path: &Path) -> Result<Module<T>, Error>
66 where
67 T: DeserializeOwned;
68}