mirror of
https://codeberg.org/icewind/netnsd.git
synced 2026-06-03 17:14:06 +02:00
track which namespaces we control
This commit is contained in:
parent
d168b4bf4d
commit
32fc90debe
5 changed files with 59 additions and 14 deletions
|
|
@ -1,11 +1,25 @@
|
|||
use serde::de::{Error, Unexpected, Visitor};
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use std::ffi::OsString;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct NamespaceName(String);
|
||||
|
||||
impl TryFrom<OsString> for NamespaceName {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: OsString) -> Result<Self, Self::Error> {
|
||||
let str = value.into_string().map_err(|_| ())?;
|
||||
if validate_name(&str) {
|
||||
Ok(NamespaceName(str))
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for NamespaceName {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
|
|
@ -80,7 +94,7 @@ fn validate_name(name: &str) -> bool {
|
|||
|
||||
#[test]
|
||||
fn test_de() {
|
||||
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
|
||||
use serde_test::{Token, assert_de_tokens, assert_de_tokens_error};
|
||||
|
||||
assert_de_tokens(&NamespaceName("foo".into()), &[Token::String("foo")]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue