email/account/config/pgp/
derive.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
4#[serde(rename_all = "kebab-case", tag = "type")]
5pub enum PgpConfig {
6 #[cfg(feature = "pgp-commands")]
7 Commands(super::PgpCommandsConfig),
8 #[cfg(not(feature = "pgp-commands"))]
9 #[serde(skip_serializing, deserialize_with = "missing_commands_feature")]
10 Commands,
11
12 #[cfg(feature = "pgp-gpg")]
13 Gpg(super::PgpGpgConfig),
14 #[cfg(not(feature = "pgp-gpg"))]
15 #[serde(skip_serializing, deserialize_with = "missing_gpg_feature")]
16 Gpg,
17
18 #[cfg(feature = "pgp-native")]
19 Native(super::PgpNativeConfig),
20 #[cfg(not(feature = "pgp-native"))]
21 #[serde(skip_serializing, deserialize_with = "missing_native_feature")]
22 Native,
23}
24
25#[cfg(not(feature = "pgp-commands"))]
26fn missing_commands_feature<'de, D: serde::Deserializer<'de>>(_: D) -> Result<(), D::Error> {
27 Err(serde::de::Error::custom(
28 "missing `pgp-commands` cargo feature",
29 ))
30}
31
32#[cfg(not(feature = "pgp-gpg"))]
33fn missing_gpg_feature<'de, D: serde::Deserializer<'de>>(_: D) -> Result<(), D::Error> {
34 Err(serde::de::Error::custom("missing `pgp-gpg` cargo feature"))
35}
36
37#[cfg(not(feature = "pgp-native"))]
38fn missing_native_feature<'de, D: serde::Deserializer<'de>>(_: D) -> Result<(), D::Error> {
39 Err(serde::de::Error::custom(
40 "missing `pgp-native` cargo feature",
41 ))
42}
43
44impl From<PgpConfig> for super::PgpConfig {
45 fn from(config: PgpConfig) -> Self {
46 match config {
47 #[cfg(feature = "pgp-commands")]
48 PgpConfig::Commands(config) => super::PgpConfig::Commands(config),
49 #[cfg(not(feature = "pgp-commands"))]
50 PgpConfig::Commands => super::PgpConfig::None,
51
52 #[cfg(feature = "pgp-gpg")]
53 PgpConfig::Gpg(config) => super::PgpConfig::Gpg(config),
54 #[cfg(not(feature = "pgp-gpg"))]
55 PgpConfig::Gpg => super::PgpConfig::None,
56
57 #[cfg(feature = "pgp-native")]
58 PgpConfig::Native(config) => super::PgpConfig::Native(config),
59 #[cfg(not(feature = "pgp-native"))]
60 PgpConfig::Native => super::PgpConfig::None,
61 }
62 }
63}