summaryrefslogtreecommitdiff
path: root/src/ser/void.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2017-01-28 23:52:52 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2017-01-29 10:22:39 +0100
commite140c2b5c5bb5abab7fcc6a9d4540aaa3bf566a6 (patch)
treefb2302cd388eb3fb78277bb88a0c99a97a2a1773 /src/ser/void.rs
parentfa8fb69da0b3a9d24bff09da3795e54d6b20a157 (diff)
Use void for the unreachable serializers
Diffstat (limited to 'src/ser/void.rs')
-rw-r--r--src/ser/void.rs122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/ser/void.rs b/src/ser/void.rs
new file mode 100644
index 0000000..4765bb7
--- /dev/null
+++ b/src/ser/void.rs
@@ -0,0 +1,122 @@
+use ser::Error;
+use serde::ser;
+use std::marker::PhantomData;
+use void;
+
+pub struct VoidSerializer<Ok> {
+ void: void::Void,
+ _marker: PhantomData<Ok>,
+}
+
+impl<Ok> ser::SerializeSeq for VoidSerializer<Ok> {
+ type Ok = Ok;
+ type Error = Error;
+
+ fn serialize_element<T: ?Sized + ser::Serialize>(&mut self,
+ _value: &T)
+ -> Result<(), Error> {
+ void::unreachable(self.void)
+ }
+
+ fn end(self) -> Result<Ok, Error> {
+ void::unreachable(self.void)
+ }
+}
+
+impl<Ok> ser::SerializeTuple for VoidSerializer<Ok> {
+ type Ok = Ok;
+ type Error = Error;
+
+ fn serialize_element<T: ?Sized + ser::Serialize>(&mut self,
+ _value: &T)
+ -> Result<(), Error> {
+ void::unreachable(self.void)
+ }
+
+ fn end(self) -> Result<Ok, Error> {
+ void::unreachable(self.void)
+ }
+}
+
+impl<Ok> ser::SerializeTupleStruct for VoidSerializer<Ok> {
+ type Ok = Ok;
+ type Error = Error;
+
+ fn serialize_field<T: ?Sized + ser::Serialize>(&mut self,
+ _value: &T)
+ -> Result<(), Error> {
+ void::unreachable(self.void)
+ }
+
+ fn end(self) -> Result<Ok, Error> {
+ void::unreachable(self.void)
+ }
+}
+
+impl<Ok> ser::SerializeTupleVariant for VoidSerializer<Ok> {
+ type Ok = Ok;
+ type Error = Error;
+
+ fn serialize_field<T: ?Sized + ser::Serialize>(&mut self,
+ _value: &T)
+ -> Result<(), Error> {
+ void::unreachable(self.void)
+ }
+
+ fn end(self) -> Result<Ok, Error> {
+ void::unreachable(self.void)
+ }
+}
+
+impl<Ok> ser::SerializeMap for VoidSerializer<Ok> {
+ type Ok = Ok;
+ type Error = Error;
+
+ fn serialize_key<T: ?Sized + ser::Serialize>(&mut self,
+ _key: &T)
+ -> Result<(), Error> {
+ void::unreachable(self.void)
+ }
+
+ fn serialize_value<T: ?Sized + ser::Serialize>(&mut self,
+ _value: &T)
+ -> Result<(), Error> {
+ void::unreachable(self.void)
+ }
+
+ fn end(self) -> Result<Ok, Error> {
+ void::unreachable(self.void)
+ }
+}
+
+impl<Ok> ser::SerializeStruct for VoidSerializer<Ok> {
+ type Ok = Ok;
+ type Error = Error;
+
+ fn serialize_field<T: ?Sized + ser::Serialize>(&mut self,
+ _key: &'static str,
+ _value: &T)
+ -> Result<(), Error> {
+ void::unreachable(self.void)
+ }
+
+ fn end(self) -> Result<Ok, Error> {
+ void::unreachable(self.void)
+ }
+}
+
+impl<Ok> ser::SerializeStructVariant for VoidSerializer<Ok> {
+ type Ok = Ok;
+ type Error = Error;
+
+ fn serialize_field<T: ?Sized + ser::Serialize>(&mut self,
+ _key: &'static str,
+ _value: &T)
+ -> Result<(), Error> {
+ void::unreachable(self.void)
+ }
+
+ fn end(self) -> Result<Ok, Error> {
+ void::unreachable(self.void)
+ }
+}