impl Clone for Encoding {
fn clone(&self) -> Self {
Encoding(self.0)
}
}
impl Serialize for Encoding {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.label())
}
}
struct EncodingVisitor;
impl<'de> Deserialize<'de> for Encoding {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
impl<'de> Visitor<'de> for EncodingVisitor {
type Value = Encoding;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a string label meeting the encoding standard https://encoding.spec.whatwg.org/#concept-encoding-get")
}
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(Encoding::for_label(v))
}
}
deserializer.deserialize_str(EncodingVisitor)
}
}