props: skip deserialization where it doesn't make sense

This commit is contained in:
Lennart
2024-11-04 21:14:54 +01:00
parent ff95d65d44
commit 0cf6e5cb92
5 changed files with 17 additions and 41 deletions

View File

@@ -1,37 +1,9 @@
use serde::de::{MapAccess, Visitor};
use serde::ser::SerializeMap;
use serde::{Deserialize, Serialize};
use serde::Serialize;
#[derive(Debug, Clone, PartialEq)]
pub struct Resourcetype(pub &'static [&'static str]);
struct ResourcetypeVisitor;
impl<'de> Visitor<'de> for ResourcetypeVisitor {
type Value = Resourcetype;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("TagList")
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'de>,
{
while map.next_key::<String>()?.is_some() {}
Ok(Resourcetype(&[]))
}
}
impl<'de> Deserialize<'de> for Resourcetype {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_map(ResourcetypeVisitor)
}
}
impl Serialize for Resourcetype {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where