mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-03 01:25:37 +00:00
config: use getset
This commit is contained in:
@@ -50,6 +50,7 @@ time = "0.3"
|
|||||||
toml = "0.8.12"
|
toml = "0.8.12"
|
||||||
chrono = { version = "0.4.37", features = ["serde"] }
|
chrono = { version = "0.4.37", features = ["serde"] }
|
||||||
|
|
||||||
|
getset = "0.1.6"
|
||||||
optional_struct = "0.5.2"
|
optional_struct = "0.5.2"
|
||||||
|
|
||||||
guarden = "0.1"
|
guarden = "0.1"
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use clap::ValueEnum;
|
|||||||
use clap::builder::PossibleValue;
|
use clap::builder::PossibleValue;
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use derive_more::{Constructor, Deref};
|
use derive_more::{Constructor, Deref};
|
||||||
|
use getset::Getters;
|
||||||
use optional_struct::Applicable;
|
use optional_struct::Applicable;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::{Debug, Display};
|
use std::fmt::{Debug, Display};
|
||||||
@@ -28,21 +29,23 @@ use std::{
|
|||||||
use strum::{Display, EnumString, VariantArray};
|
use strum::{Display, EnumString, VariantArray};
|
||||||
use tokio::io::AsyncReadExt as _;
|
use tokio::io::AsyncReadExt as _;
|
||||||
|
|
||||||
#[derive(Derivative, Debug, Clone, Constructor, Deref, Deserialize)]
|
#[derive(Derivative, Debug, Clone, Constructor, Getters, Deref, Deserialize)]
|
||||||
#[derivative(PartialEq(bound = "Parsed: PartialEq"))]
|
#[derivative(PartialEq(bound = "Parsed: PartialEq"))]
|
||||||
#[serde(try_from = "Raw")]
|
#[serde(try_from = "Raw")]
|
||||||
#[serde(
|
#[serde(
|
||||||
bound = "Raw: Deserialize<'de>, <ConfigBase<Raw, Parsed, Data> as TryFrom<Raw>>::Error: Display"
|
bound = "Raw: Deserialize<'de>, <ConfigBase<Raw, Parsed, Data> as TryFrom<Raw>>::Error: Display"
|
||||||
)]
|
)]
|
||||||
pub struct ConfigBase<Raw, Parsed, Data>
|
pub struct ConfigBase<Raw, Parsed, Data = ()>
|
||||||
where
|
where
|
||||||
Raw: Applicable<Base = Parsed>,
|
Raw: Applicable<Base = Parsed>,
|
||||||
ConfigBase<Raw, Parsed, Data>: TryFrom<Raw, Error: Debug>,
|
ConfigBase<Raw, Parsed, Data>: TryFrom<Raw>,
|
||||||
{
|
{
|
||||||
#[derivative(PartialEq = "ignore")]
|
|
||||||
raw: Raw,
|
|
||||||
#[deref]
|
#[deref]
|
||||||
parsed: Parsed,
|
parsed: Parsed,
|
||||||
|
#[getset(get)]
|
||||||
|
#[derivative(PartialEq = "ignore")]
|
||||||
|
raw: Raw,
|
||||||
|
#[getset(get)]
|
||||||
#[derivative(PartialEq = "ignore")]
|
#[derivative(PartialEq = "ignore")]
|
||||||
data: Data,
|
data: Data,
|
||||||
}
|
}
|
||||||
@@ -75,14 +78,14 @@ where
|
|||||||
Raw: Applicable<Base = Parsed>,
|
Raw: Applicable<Base = Parsed>,
|
||||||
ConfigBase<Raw, Parsed, Data>: TryFrom<Raw, Error: Debug>,
|
ConfigBase<Raw, Parsed, Data>: TryFrom<Raw, Error: Debug>,
|
||||||
{
|
{
|
||||||
pub fn into_raw(self) -> Raw {
|
|
||||||
self.raw
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn into_parsed(self) -> Parsed {
|
pub fn into_parsed(self) -> Parsed {
|
||||||
self.parsed
|
self.parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_raw(self) -> Raw {
|
||||||
|
self.raw
|
||||||
|
}
|
||||||
|
|
||||||
pub fn into_data(self) -> Data {
|
pub fn into_data(self) -> Data {
|
||||||
self.data
|
self.data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ impl From<DnsConfigRaw> for DnsConfig {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let parsed = raw.clone().build(default);
|
let parsed = raw.clone().build(default);
|
||||||
Self::new(raw, parsed, ())
|
Self::new(parsed, raw, ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ impl TryFrom<ZoneConfigRaw> for ZoneConfig {
|
|||||||
let data = (&parsed).into();
|
let data = (&parsed).into();
|
||||||
let _ = Zone::try_from(&data)?; // validation
|
let _ = Zone::try_from(&data)?; // validation
|
||||||
|
|
||||||
Ok(Self::new(raw, parsed, data))
|
Ok(Self::new(parsed, raw, data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +107,6 @@ impl ZoneConfig {
|
|||||||
|
|
||||||
let data = (&parsed).into();
|
let data = (&parsed).into();
|
||||||
|
|
||||||
Self::new(Default::default(), parsed, data)
|
Self::new(parsed, Default::default(), data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user