pub struct SerializerConfig { /* private fields */ }Expand description
Configures how values are serialized to query strings.
The value has to serialize to a map (for instance a struct or a map
type), or to a sequence of key-value pairs (like Vec<(&str, &str)>).
Null values (like None) of map entries are skipped, null values in
sequences are written as empty values. Maps and sequences that are
empty are not written as query strings cannot represent them.
Keys and values are percent-encoded like application/x-www-form-urlencoded
(ASCII alphanumerics and *-._ are kept, space is written as +).
Numbers are written with the shortest text that reads back as the same
value, booleans as true and false and bytes as base64 (or the
BytesFormat of the context).
Implementations§
Source§impl SerializerConfig
impl SerializerConfig
Sourcepub const fn new() -> SerializerConfig
pub const fn new() -> SerializerConfig
Creates the default configuration.
Sourcepub const fn builder() -> SerializerConfigBuilder
pub const fn builder() -> SerializerConfigBuilder
Returns a builder for the configuration (see SerializerConfigBuilder).
Sourcepub const fn into_builder(self) -> SerializerConfigBuilder
pub const fn into_builder(self) -> SerializerConfigBuilder
Returns a builder that starts with this configuration.
Sourcepub fn set_context(&mut self, context: Context)
pub fn set_context(&mut self, context: Context)
Sets the context the values are serialized in.
The values of the context are the defaults of the extension values
of the state (see Context), for instance
the BytesFormat. The serializers and
writers created with the configuration use this context. A context set on
the driver takes precedence.
Sourcepub const fn set_arrays(&mut self, format: ArrayFormat)
pub const fn set_arrays(&mut self, format: ArrayFormat)
Sets how sequences are written.
The default is ArrayFormat::Repeat.
Sourcepub const fn set_nesting(&mut self, nesting: Nesting)
pub const fn set_nesting(&mut self, nesting: Nesting)
Sets how the keys of nested maps are written.
The default is Nesting::Brackets (a[b]=1), with
Nesting::Dots they are written as a.b=1. With
Nesting::Flat nested maps are an error.
Sourcepub const fn set_space_as_plus(&mut self, yes: bool)
pub const fn set_space_as_plus(&mut self, yes: bool)
Sets if spaces are written as + (the default) or as %20.
Sourcepub fn to_string<T: Serialize + ?Sized>(
&self,
value: &T,
) -> Result<String, Error>
pub fn to_string<T: Serialize + ?Sized>( &self, value: &T, ) -> Result<String, Error>
Serializes the given value.
Sourcepub fn to_string_with<F, T: Serialize + ?Sized>(
&self,
value: &T,
setup: F,
) -> Result<String, Error>where
F: FnOnce(&mut SerializeDriver<'_>),
pub fn to_string_with<F, T: Serialize + ?Sized>(
&self,
value: &T,
setup: F,
) -> Result<String, Error>where
F: FnOnce(&mut SerializeDriver<'_>),
Serializes the given value with a configured driver.
The callback is invoked with the driver before the serialization
starts, for instance to add Layers.
Source§impl SerializerConfig
impl SerializerConfig
Sourcepub fn writer<W: Write>(&self, writer: W) -> Writer<W, Serializer>
pub fn writer<W: Write>(&self, writer: W) -> Writer<W, Serializer>
Creates a writer of form data (see
deser::io::Writer).
The parameters of more than one value are joined. The output of large values is written in parts while they are serialized.