Skip to content

Commit

Permalink
deprecate compact serialization of some types
Browse files Browse the repository at this point in the history
Binary, HexBinary, Checksum
  • Loading branch information
uint committed Apr 24, 2024
1 parent 9f88e7c commit 1736004
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions packages/std/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ impl Serialize for Binary {
where
S: ser::Serializer,
{
serializer.serialize_str(&self.to_base64())
if serializer.is_human_readable() {
serializer.serialize_str(&self.to_base64())
} else {
panic!("Binary is only intended to be used with JSON serialization for now")

Check warning on line 220 in packages/std/src/binary.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/binary.rs#L220

Added line #L220 was not covered by tests
}
}
}

Expand All @@ -224,7 +228,11 @@ impl<'de> Deserialize<'de> for Binary {
where
D: Deserializer<'de>,
{
deserializer.deserialize_str(Base64Visitor)
if deserializer.is_human_readable() {
deserializer.deserialize_str(Base64Visitor)
} else {
panic!("Binary is only intended to be used with JSON serialization for now")

Check warning on line 234 in packages/std/src/binary.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/binary.rs#L234

Added line #L234 was not covered by tests
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions packages/std/src/hex_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ impl Serialize for HexBinary {
where
S: ser::Serializer,
{
serializer.serialize_str(&self.to_hex())
if serializer.is_human_readable() {
serializer.serialize_str(&self.to_hex())
} else {
panic!("HexBinary is only intended to be used with JSON serialization for now")

Check warning on line 215 in packages/std/src/hex_binary.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/hex_binary.rs#L215

Added line #L215 was not covered by tests
}
}
}

Expand All @@ -219,7 +223,11 @@ impl<'de> Deserialize<'de> for HexBinary {
where
D: Deserializer<'de>,
{
deserializer.deserialize_str(HexVisitor)
if deserializer.is_human_readable() {
deserializer.deserialize_str(HexVisitor)
} else {
panic!("HexBinary is only intended to be used with JSON serialization for now")

Check warning on line 229 in packages/std/src/hex_binary.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/hex_binary.rs#L229

Added line #L229 was not covered by tests
}
}
}

Expand Down

0 comments on commit 1736004

Please sign in to comment.