mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-06 12:39:51 +00:00
config: use getset
This commit is contained in:
@@ -50,6 +50,7 @@ time = "0.3"
|
||||
toml = "0.8.12"
|
||||
chrono = { version = "0.4.37", features = ["serde"] }
|
||||
|
||||
getset = "0.1.6"
|
||||
optional_struct = "0.5.2"
|
||||
|
||||
guarden = "0.1"
|
||||
|
||||
@@ -16,6 +16,7 @@ use clap::ValueEnum;
|
||||
use clap::builder::PossibleValue;
|
||||
use derivative::Derivative;
|
||||
use derive_more::{Constructor, Deref};
|
||||
use getset::Getters;
|
||||
use optional_struct::Applicable;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Debug, Display};
|
||||
@@ -28,21 +29,23 @@ use std::{
|
||||
use strum::{Display, EnumString, VariantArray};
|
||||
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"))]
|
||||
#[serde(try_from = "Raw")]
|
||||
#[serde(
|
||||
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
|
||||
Raw: Applicable<Base = Parsed>,
|
||||
ConfigBase<Raw, Parsed, Data>: TryFrom<Raw, Error: Debug>,
|
||||
ConfigBase<Raw, Parsed, Data>: TryFrom<Raw>,
|
||||
{
|
||||
#[derivative(PartialEq = "ignore")]
|
||||
raw: Raw,
|
||||
#[deref]
|
||||
parsed: Parsed,
|
||||
#[getset(get)]
|
||||
#[derivative(PartialEq = "ignore")]
|
||||
raw: Raw,
|
||||
#[getset(get)]
|
||||
#[derivative(PartialEq = "ignore")]
|
||||
data: Data,
|
||||
}
|
||||
@@ -75,14 +78,14 @@ where
|
||||
Raw: Applicable<Base = Parsed>,
|
||||
ConfigBase<Raw, Parsed, Data>: TryFrom<Raw, Error: Debug>,
|
||||
{
|
||||
pub fn into_raw(self) -> Raw {
|
||||
self.raw
|
||||
}
|
||||
|
||||
pub fn into_parsed(self) -> Parsed {
|
||||
self.parsed
|
||||
}
|
||||
|
||||
pub fn into_raw(self) -> Raw {
|
||||
self.raw
|
||||
}
|
||||
|
||||
pub fn into_data(self) -> Data {
|
||||
self.data
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ impl From<DnsConfigRaw> for DnsConfig {
|
||||
};
|
||||
|
||||
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 _ = 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();
|
||||
|
||||
Self::new(Default::default(), parsed, data)
|
||||
Self::new(parsed, Default::default(), data)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user