Serialize to binary if the serde format is not human readable

This implements the KISS suggested in https://github.com/serde-rs/serde/issues/790.
It is possible that one of the other approaches may be better but this
seemed like the simplest one to reignite som discussion.

Personally I find the original suggestion of adding two traits perhaps slightly
cleaner in theory but I think it ends up more complicated in the end
since the added traits also need to be duplicated to to the `Seed`
traits.

Closes #790
This commit is contained in:
Markus Westerlind
2017-09-07 15:56:22 +02:00
parent d4042872f5
commit 0dccbb1f11
8 changed files with 115 additions and 8 deletions
+6
View File
@@ -1011,6 +1011,12 @@ pub trait Deserializer<'de>: Sized {
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>;
/// Returns whether the serialized data is human readable or not.
///
/// Some formats are not intended to be human readable. For these formats
/// a type being serialized may opt to serialize into a more compact form.
fn is_human_readable(&self) -> bool { true }
}
////////////////////////////////////////////////////////////////////////////////
+6
View File
@@ -1363,6 +1363,12 @@ pub trait Serializer: Sized {
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: Display;
/// Returns wheter the data format is human readable or not.
///
/// Some formats are not intended to be human readable. For these formats
/// a type being serialized may opt to serialize into a more compact form.
fn is_human_readable(&self) -> bool { true }
}
/// Returned from `Serializer::serialize_seq`.