//! Hacky serializer that only allows `u8` use serde::ser::Impossible; use serde::Serialize; use std::fmt; pub(crate) struct OnlyBytes; pub(crate) struct Nope; impl std::error::Error for Nope { } impl std::fmt::Display for Nope { fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { Ok(()) } } impl std::fmt::Debug for Nope { fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { Ok(()) } } impl serde::ser::Error for Nope { fn custom(_: T) -> Self { Self } } impl serde::de::Error for Nope { fn custom(_: T) -> Self { Self } } impl serde::Serializer for OnlyBytes { type Error = Nope; type Ok = u8; type SerializeMap = Impossible; type SerializeSeq = Impossible; type SerializeStruct = Impossible; type SerializeStructVariant = Impossible; type SerializeTuple = Impossible; type SerializeTupleStruct = Impossible; type SerializeTupleVariant = Impossible; fn serialize_u8(self, val: u8) -> Result { Ok(val) } fn serialize_bool(self, _: bool) -> Result { Err(Nope) } fn serialize_i8(self, _: i8) -> Result { Err(Nope) } fn serialize_i16(self, _: i16) -> Result { Err(Nope) } fn serialize_i32(self, _: i32) -> Result { Err(Nope) } fn serialize_i64(self, _: i64) -> Result { Err(Nope) } fn serialize_u16(self, _: u16) -> Result { Err(Nope) } fn serialize_u32(self, _: u32) -> Result { Err(Nope) } fn serialize_u64(self, _: u64) -> Result { Err(Nope) } fn serialize_f32(self, _: f32) -> Result { Err(Nope) } fn serialize_f64(self, _: f64) -> Result { Err(Nope) } fn serialize_char(self, _: char) -> Result { Err(Nope) } fn serialize_str(self, _: &str) -> Result { Err(Nope) } fn serialize_bytes(self, _: &[u8]) -> Result { Err(Nope) } fn serialize_none(self) -> Result { Err(Nope) } fn serialize_some(self, _: &T) -> Result where T: Serialize + ?Sized { Err(Nope) } fn serialize_unit(self) -> Result { Err(Nope) } fn serialize_unit_struct(self, _: &'static str) -> Result { Err(Nope) } fn serialize_unit_variant(self, _: &'static str, _: u32, _: &'static str) -> Result { Err(Nope) } fn serialize_newtype_struct(self, _: &'static str, _: &T) -> Result where T: Serialize + ?Sized { Err(Nope) } fn serialize_newtype_variant(self, _: &'static str, _: u32, _: &'static str, _: &T) -> Result where T: Serialize + ?Sized { Err(Nope) } fn serialize_seq(self, _: Option) -> Result { Err(Nope) } fn serialize_tuple(self, _: usize) -> Result { Err(Nope) } fn serialize_tuple_struct(self, _: &'static str, _: usize) -> Result { Err(Nope) } fn serialize_tuple_variant(self, _: &'static str, _: u32, _: &'static str, _: usize) -> Result { Err(Nope) } fn serialize_map(self, _: Option) -> Result { Err(Nope) } fn serialize_struct(self, _: &'static str, _: usize) -> Result { Err(Nope) } fn serialize_struct_variant(self, _: &'static str, _: u32, _: &'static str, _: usize) -> Result { Err(Nope) } fn collect_seq(self, _: I) -> Result where I: IntoIterator, ::Item: Serialize { Err(Nope) } fn collect_map(self, _: I) -> Result where K: Serialize, V: Serialize, I: IntoIterator { Err(Nope) } fn collect_str(self, _: &T) -> Result where T: fmt::Display + ?Sized { Err(Nope) } }