mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-08-07 05:25:44 +00:00
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:
@@ -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 }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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`.
|
||||
|
||||
Reference in New Issue
Block a user