Skip to content

Commit

Permalink
Obey settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Sep 30, 2024
1 parent 49292ec commit c20fec5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class SerializeImplGenerator(private val codegenContext: CodegenContext) {
implSerializeConfigured(symbolBuilder(shape, numericType).build()) {
rustTemplate(
"""
if !self.settings.out_of_range_floats_as_strings {
return self.value.serialize(serializer)
}
if self.value.is_nan() {
serializer.serialize_str("NaN")
} else if *self.value == #{ty}::INFINITY {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ class SerdeDecoratorTest {
settings.redact_sensitive_fields = true;
let serialized = #{serde_json}::to_string(&input.serialize_ref(&settings)).expect("failed to serialize");
assert_eq!(serialized, ${expectedRedacted.dq()});
settings.out_of_range_floats_as_strings = false;
let serialized = #{serde_json}::to_string(&input.serialize_ref(&settings)).expect("failed to serialize");
assert_ne!(serialized, ${expectedRedacted.dq()});
""",
*codegenScope,
)
Expand Down

0 comments on commit c20fec5

Please sign in to comment.