From 6e71ba43eb6bd62f2b567224e387333016bd3a5c Mon Sep 17 00:00:00 2001 From: Sam Scott Date: Sat, 20 May 2017 22:07:44 +0100 Subject: Rewrite of most components. Simplify `ser` logic, and expand `de` functionality. --- src/ser/key.rs | 108 --------------------------------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 src/ser/key.rs (limited to 'src/ser/key.rs') diff --git a/src/ser/key.rs b/src/ser/key.rs deleted file mode 100644 index 10f1fff..0000000 --- a/src/ser/key.rs +++ /dev/null @@ -1,108 +0,0 @@ -use ser::Error; -use ser::part::Sink; -use serde::Serialize; -use serde::ser::{SerializeSeq, SerializeStruct}; -use std::borrow::Cow; -use std::ops::Deref; - -pub enum Key<'key> { - Static(&'static str), - Dynamic(Cow<'key, str>), -} - -impl<'key> Deref for Key<'key> { - type Target = str; - - fn deref(&self) -> &str { - match *self { - Key::Static(key) => key, - Key::Dynamic(ref key) => key, - } - } -} - -impl<'key> From> for Cow<'static, str> { - fn from(key: Key<'key>) -> Self { - match key { - Key::Static(key) => key.into(), - Key::Dynamic(key) => key.into_owned().into(), - } - } -} - -pub struct KeySink { - end: End, -} - -impl KeySink - where End: for<'key> FnOnce(Key<'key>) -> Result, -{ - pub fn new(end: End) -> Self { - KeySink { end: end } - } -} - -impl Sink for KeySink - where End: for<'key> FnOnce(Key<'key>) -> Result, -{ - fn serialize_static_str(self, value: &'static str) -> Result { - (self.end)(Key::Static(value)) - } - - fn serialize_str(self, value: &str) -> Result { - (self.end)(Key::Dynamic(value.into())) - } - - fn serialize_string(self, value: String) -> Result { - (self.end)(Key::Dynamic(value.into())) - } - - fn serialize_none(self) -> Result { - Err(self.unsupported()) - } - - fn serialize_some(self, - _value: &T) - -> Result { - Err(self.unsupported()) - } - - fn unsupported(&self) -> Error { - Error::Custom("unsupported key".into()) - } -} - -impl SerializeStruct for KeySink - where End: for<'key> FnOnce(Key<'key>) -> Result, -{ - type Ok = Ok; - type Error = Error; - - fn serialize_field(&mut self, - _key: &'static str, - _value: &T) - -> Result<(), Error> { - Err(self.unsupported()) - } - - fn end(self) -> Result { - Err(self.unsupported()) - } -} - -impl SerializeSeq for KeySink - where End: for<'key> FnOnce(Key<'key>) -> Result, -{ - type Ok = Ok; - type Error = Error; - - fn serialize_element(&mut self, - _value: &T) - -> Result<(), Error> { - Err(self.unsupported()) - } - - fn end(self) -> Result { - Err(self.unsupported()) - } -} -- cgit v1.2.3