q
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
use crate::route::error::ApiError;
|
use crate::route::error::ApiError;
|
||||||
use crate::utils::query_parser::{QueryType, parse_query};
|
use crate::utils::query::parser::{QueryType, parse_query};
|
||||||
use axum::Json;
|
use axum::Json;
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ pub mod wake;
|
|||||||
// this is so bad
|
// this is so bad
|
||||||
pub mod ping;
|
pub mod ping;
|
||||||
pub mod query;
|
pub mod query;
|
||||||
pub mod query_parser;
|
|
||||||
pub mod route;
|
pub mod route;
|
||||||
|
|
||||||
// no custom ip deserializer needed when using axum_extra::extract::Query
|
// no custom ip deserializer needed when using axum_extra::extract::Query
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
use macaddr::MacAddr;
|
||||||
|
use serde::{self, Deserialize, Deserializer, de::Error as DeError};
|
||||||
|
use serde::{Serialize, Serializer, de};
|
||||||
|
|
||||||
|
pub fn _serialize_macs<S>(macs: &[MacAddr], serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let strings: Vec<String> = macs.iter().map(|m| m.to_string()).collect();
|
||||||
|
serde::Serialize::serialize(&strings, serializer)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Serialize a MacAddr as a string
|
||||||
|
pub fn serialize<S>(mac: &MacAddr, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
serializer.serialize_str(&mac.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deserialize a MacAddr from a string
|
||||||
|
pub fn _deserialize<'de, D>(deserializer: D) -> Result<MacAddr, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let s = <String as serde::Deserialize>::deserialize(deserializer)?;
|
||||||
|
s.parse::<MacAddr>().map_err(DeError::custom)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod option_mac {
|
||||||
|
use super::*;
|
||||||
|
/// serialize an [`Option<MacAddr>`]
|
||||||
|
pub fn serialize<S: Serializer>(bro: &Option<MacAddr>, ser: S) -> Result<S::Ok, S::Error> {
|
||||||
|
Option::<String>::serialize(&bro.as_ref().map(ToString::to_string), ser)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// deserialize an [`Option<MacAddr>`]
|
||||||
|
pub fn deserialize<'de, D>(des: D) -> Result<Option<MacAddr>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
Option::<&str>::deserialize(des)?
|
||||||
|
.map(str::parse)
|
||||||
|
.transpose()
|
||||||
|
.map_err(de::Error::custom)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -100,52 +100,4 @@ pub fn boolish_str(s: &str) -> bool {
|
|||||||
&& t.parse::<u64>().map(|n| n != 0).unwrap_or(false))
|
&& t.parse::<u64>().map(|n| n != 0).unwrap_or(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod mac {
|
pub mod mac;
|
||||||
use macaddr::MacAddr;
|
|
||||||
use serde::{self, Deserialize, Deserializer, de::Error as DeError};
|
|
||||||
use serde::{Serialize, Serializer, de};
|
|
||||||
|
|
||||||
pub fn _serialize_macs<S>(macs: &[MacAddr], serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
let strings: Vec<String> = macs.iter().map(|m| m.to_string()).collect();
|
|
||||||
serde::Serialize::serialize(&strings, serializer)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Serialize a MacAddr as a string
|
|
||||||
pub fn serialize<S>(mac: &MacAddr, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
serializer.serialize_str(&mac.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deserialize a MacAddr from a string
|
|
||||||
pub fn _deserialize<'de, D>(deserializer: D) -> Result<MacAddr, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let s = <String as serde::Deserialize>::deserialize(deserializer)?;
|
|
||||||
s.parse::<MacAddr>().map_err(DeError::custom)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod option_mac {
|
|
||||||
use super::*;
|
|
||||||
/// serialize an [`Option<MacAddr>`]
|
|
||||||
pub fn serialize<S: Serializer>(bro: &Option<MacAddr>, ser: S) -> Result<S::Ok, S::Error> {
|
|
||||||
Option::<String>::serialize(&bro.as_ref().map(ToString::to_string), ser)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// deserialize an [`Option<MacAddr>`]
|
|
||||||
pub fn deserialize<'de, D>(des: D) -> Result<Option<MacAddr>, D::Error>
|
|
||||||
where
|
|
||||||
D: serde::Deserializer<'de>,
|
|
||||||
{
|
|
||||||
Option::<&str>::deserialize(des)?
|
|
||||||
.map(str::parse)
|
|
||||||
.transpose()
|
|
||||||
.map_err(de::Error::custom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod dev;
|
pub mod dev;
|
||||||
pub mod leases;
|
pub mod leases;
|
||||||
pub mod macs;
|
pub mod macs;
|
||||||
|
pub mod parser;
|
||||||
|
|
||||||
pub use leases::*;
|
pub use leases::*;
|
||||||
pub use macs::*;
|
pub use macs::*;
|
||||||
Reference in New Issue
Block a user