module_util/file/
mod.rs

1//! The [`File`] evaluator for working with modules from files.
2
3#[allow(clippy::module_inception)]
4mod file;
5mod format;
6
7pub use self::file::{File, read};
8pub use self::format::{Format, Imports, Module};
9
10macro_rules! formats {
11    ($(
12        $mod:ident::$name:ident $(if $cfg:meta)?,
13    )*) => { $(
14        $(#[cfg($cfg)])?
15        mod $mod;
16        $(#[cfg($cfg)])?
17        pub use self::$mod::$name;
18
19        $(#[cfg($cfg)])?
20        impl<T> File<T, $name> {
21            #[doc = concat!("Create a new [`File`] that reads [`", stringify!($name), "`] files.")]
22            #[doc = ""]
23            #[doc = concat!("See: [`", stringify!($name), "`].")]
24            #[doc = ""]
25            #[doc = concat!("Equivalent to: `File::new(", stringify!($name), "::default())`")]
26            pub fn $mod() -> Self {
27                Self::new($name::default())
28            }
29        }
30
31        $(#[cfg($cfg)])?
32        #[doc = concat!("Read the module at `path` with [`", stringify!($name), "`].")]
33        #[doc = ""]
34        #[doc = concat!("See: [`", stringify!($name), "`].")]
35        pub fn $mod<T>(path: impl AsRef<std::path::Path>) -> Result<T, module::Error>
36        where
37            T: module::Merge + serde::de::DeserializeOwned,
38        {
39            read(path, $name::default())
40        }
41    )* };
42}
43
44formats! {
45    json::Json if feature = "json",
46    toml::Toml if feature = "toml",
47    yaml::Yaml if feature = "yaml",
48}