1#![allow(clippy::multiple_crate_versions)]
2
3use std::{marker::Sized, path::PathBuf};
4
5pub use derive_macros::*;
6#[cfg(feature = "directories")]
7pub use directories::{self};
8#[cfg(feature = "dirs")]
9pub use dirs::{self};
10#[cfg(feature = "etcetera")]
11pub use etcetera::{self};
12#[cfg(feature = "json")]
13pub use json::{self};
14#[cfg(feature = "toml")]
15pub use toml::{self};
16#[cfg(feature = "yaml")]
17pub use yaml::{self};
18
19#[derive(Debug, thiserror::Error)]
20pub enum ConfigError {
21 #[error("None")]
22 None,
23
24 #[cfg(feature = "etcetera")]
25 #[error(transparent)]
26 HomeDir(#[from] etcetera::HomeDirError),
27
28 #[error(transparent)]
29 Io(#[from] std::io::Error),
30
31 #[cfg(feature = "json")]
32 #[error(transparent)]
33 Json(#[from] json::Error),
34
35 #[cfg(feature = "toml")]
36 #[error(transparent)]
37 TomlDe(#[from] toml::de::Error),
38
39 #[cfg(feature = "toml")]
40 #[error(transparent)]
41 TomlSer(#[from] toml::ser::Error),
42
43 #[cfg(feature = "yaml")]
44 #[error(transparent)]
45 Yaml(#[from] yaml::Error),
46}
47
48#[duplicate::duplicate_item(
49 language_struct_name;
50 [ DeriveJsonConfig ];
51 [ DeriveTomlConfig ];
52 [ DeriveYamlConfig ];
53)]
54pub trait language_struct_name {
55 fn path() -> Result<PathBuf, ConfigError>;
58
59 fn save(&self) -> Result<(), ConfigError>;
62
63 fn and_save(self) -> Result<Self, ConfigError>
66 where
67 Self: Sized;
68
69 fn load() -> Result<Self, ConfigError>
72 where
73 Self: Sized;
74}