Document that is_human_readable == false is a breaking change

This commit is contained in:
Markus Westerlind 2017-09-11 17:18:35 +02:00
parent a52f436788
commit c2474bf6ee
3 changed files with 16 additions and 3 deletions

View File

@ -1016,6 +1016,9 @@ pub trait Deserializer<'de>: Sized {
///
/// 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.
///
/// NOTE: Implementing this method and returning `false` is considered a breaking
/// change as it may alter how any given type tries to deserialize itself.
fn is_human_readable(&self) -> bool { true }
}

View File

@ -506,9 +506,16 @@ impl Serialize for net::IpAddr {
where
S: Serializer,
{
match *self {
net::IpAddr::V4(ref a) => a.serialize(serializer),
net::IpAddr::V6(ref a) => a.serialize(serializer),
if serializer.is_human_readable() {
match *self {
net::IpAddr::V4(ref a) => a.serialize(serializer),
net::IpAddr::V6(ref a) => a.serialize(serializer),
}
} else {
match *self {
net::IpAddr::V4(ref a) => (0u8, a).serialize(serializer),
net::IpAddr::V6(ref a) => (1u8, a).serialize(serializer),
}
}
}
}

View File

@ -1368,6 +1368,9 @@ pub trait Serializer: Sized {
///
/// 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.
///
/// NOTE: Implementing this method and returning `false` is considered a breaking
/// change as it may alter how any given type tries to serialize itself.
fn is_human_readable(&self) -> bool { true }
}