From f05368ed24aab0c74d419d7de6a3d545d1da927d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 4 Apr 2017 19:04:47 -0700 Subject: [PATCH] Remove the no_std implementation of collect_str --- serde/src/ser/mod.rs | 13 ++++--------- serde/src/ser/private.rs | 7 +++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index ad03b61f..fb9ef2dd 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -654,8 +654,9 @@ pub trait Serializer: Sized { /// Serialize a string produced by an implementation of `Display`. /// - /// The default implementation returns an error unconditionally when - /// compiled with `no_std`. + /// Serializers that use `no_std` are required to provide an implementation + /// of this method. If no more sensible behavior is possible, the + /// implementation is expected to return an error. /// /// ```rust /// # use serde::{Serialize, Serializer}; @@ -676,13 +677,7 @@ pub trait Serializer: Sized { /// ``` #[cfg(not(any(feature = "std", feature = "collections")))] fn collect_str(self, value: &T) -> Result - where T: Display - { - // TODO https://github.com/serde-rs/serde/issues/805 - // Remove this impl and force no_std formats to implement collect_str. - let _ = value; - Err(Error::custom("this no_std format does not support serializing strings with collect_str")) - } + where T: Display; } /// Returned from `Serializer::serialize_seq` and diff --git a/serde/src/ser/private.rs b/serde/src/ser/private.rs index 0297c8ac..6e30cb72 100644 --- a/serde/src/ser/private.rs +++ b/serde/src/ser/private.rs @@ -312,4 +312,11 @@ impl Serializer for TaggedSerializer try!(map.serialize_key(inner_variant)); Ok(SerializeStructVariantAsMapValue::new(map, inner_variant, len)) } + + #[cfg(not(any(feature = "std", feature = "collections")))] + fn collect_str(self, _: &T) -> Result + where T: Display + { + Err(self.bad_type(Unsupported::String)) + } }