mirror of
https://codeberg.org/icewind/netnsd.git
synced 2026-06-03 17:14:06 +02:00
basic reloading
This commit is contained in:
parent
a4c7b3c1c9
commit
78e716f949
9 changed files with 562 additions and 32 deletions
|
|
@ -28,7 +28,7 @@ impl<'de> Deserialize<'de> for ForwardDestination {
|
|||
{
|
||||
struct ForwardDestinationVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ForwardDestinationVisitor {
|
||||
impl Visitor<'_> for ForwardDestinationVisitor {
|
||||
type Value = ForwardDestination;
|
||||
|
||||
fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
|
||||
|
|
@ -75,7 +75,7 @@ impl<'de> Deserialize<'de> for ForwardDestination {
|
|||
}
|
||||
let addr = v
|
||||
.parse()
|
||||
.map_err(|_| E::invalid_value(Unexpected::Str(&v), &self))?;
|
||||
.map_err(|_| E::invalid_value(Unexpected::Str(v), &self))?;
|
||||
Ok(ForwardDestination { addr })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ impl Config {
|
|||
error,
|
||||
path: path.to_owned(),
|
||||
})?;
|
||||
Ok(config
|
||||
config
|
||||
.validate(path)
|
||||
.map_err(|error| ConfigError::Validation {
|
||||
error,
|
||||
path: path.to_owned(),
|
||||
})?)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
pub fn reload(&self) -> Result<Config, ConfigError> {
|
||||
Self::load(&self.path)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::path::Path;
|
|||
use serde::{Deserialize, Deserializer};
|
||||
use serde::de::{Error, Unexpected, Visitor};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct NamespaceName(String);
|
||||
|
||||
impl Display for NamespaceName {
|
||||
|
|
@ -37,7 +37,7 @@ impl<'de> Deserialize<'de> for NamespaceName {
|
|||
{
|
||||
struct NamespaceNameVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for NamespaceNameVisitor {
|
||||
impl Visitor<'_> for NamespaceNameVisitor {
|
||||
type Value = NamespaceName;
|
||||
|
||||
fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
|
||||
|
|
@ -82,7 +82,7 @@ fn validate_name(name: &str) -> bool {
|
|||
fn test_de() {
|
||||
use serde_test::{Token, assert_de_tokens, assert_de_tokens_error};
|
||||
|
||||
assert_de_tokens(&NamespaceName("foo".into()), &[Token::String("foo")]);;
|
||||
assert_de_tokens(&NamespaceName("foo".into()), &[Token::String("foo")]);
|
||||
|
||||
assert_de_tokens_error::<NamespaceName>(
|
||||
&[Token::String("foo/bar")],
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl<'de> Deserialize<'de> for ForwardSource {
|
|||
{
|
||||
struct ForwardSourceVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for ForwardSourceVisitor {
|
||||
impl Visitor<'_> for ForwardSourceVisitor {
|
||||
type Value = ForwardSource;
|
||||
|
||||
fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
|
||||
|
|
@ -61,7 +61,7 @@ impl<'de> Deserialize<'de> for ForwardSource {
|
|||
.map_err(|_| E::invalid_value(Unexpected::Unsigned(v), &self))?;
|
||||
self.visit_u16(v)
|
||||
}
|
||||
|
||||
|
||||
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
|
|
@ -85,7 +85,7 @@ impl<'de> Deserialize<'de> for ForwardSource {
|
|||
}
|
||||
let addr = v
|
||||
.parse()
|
||||
.map_err(|_| E::invalid_value(Unexpected::Str(&v), &self))?;
|
||||
.map_err(|_| E::invalid_value(Unexpected::Str(v), &self))?;
|
||||
Ok(ForwardSource::Ip(addr))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue