Module aws_smithy_types::primitive
source · Expand description
Utilities for formatting and parsing primitives
Smithy protocols have specific behavior for serializing & deserializing floats, specifically:
- NaN should be serialized as
NaN
- Positive infinity should be serialized as
Infinity
- Negative infinity should be serialized as
-Infinity
This module defines the Parse
trait which
enables parsing primitive values (numbers & booleans) that follow
these rules and Encoder
, a struct that enables
allocation-free serialization.
Examples
Parsing
use aws_smithy_types::primitive::Parse;
let parsed = f64::parse_smithy_primitive("123.4").expect("valid float");
Encoding
use aws_smithy_types::primitive::Encoder;
assert_eq!("123.4", Encoder::from(123.4).encode());
assert_eq!("Infinity", Encoder::from(f64::INFINITY).encode());
assert_eq!("true", Encoder::from(true).encode());
Structs
- Primitive Type Encoder
- An error during primitive parsing
Traits
- Sealed trait for custom parsing of primitive types