Struct url::form_urlencoded::Serializer
source · pub struct Serializer<T: Target> { /* private fields */ }
Expand description
Implementations§
source§impl<T: Target> Serializer<T>
impl<T: Target> Serializer<T>
sourcepub fn new(target: T) -> Self
pub fn new(target: T) -> Self
Create a new application/x-www-form-urlencoded
serializer for the given target.
If the target is non-empty,
its content is assumed to already be in application/x-www-form-urlencoded
syntax.
sourcepub fn for_suffix(target: T, start_position: usize) -> Self
pub fn for_suffix(target: T, start_position: usize) -> Self
Create a new application/x-www-form-urlencoded
serializer
for a suffix of the given target.
If that suffix is non-empty,
its content is assumed to already be in application/x-www-form-urlencoded
syntax.
sourcepub fn clear(&mut self) -> &mut Self
pub fn clear(&mut self) -> &mut Self
Remove any existing name/value pair.
Panics if called after .finish()
.
sourcepub fn encoding_override(&mut self, new: Option<EncodingRef>) -> &mut Self
pub fn encoding_override(&mut self, new: Option<EncodingRef>) -> &mut Self
Set the character encoding to be used for names and values before percent-encoding.
sourcepub fn custom_encoding_override<F>(&mut self, encode: F) -> &mut Selfwhere
F: FnMut(&str) -> Cow<'_, [u8]> + 'static,
pub fn custom_encoding_override<F>(&mut self, encode: F) -> &mut Selfwhere
F: FnMut(&str) -> Cow<'_, [u8]> + 'static,
Set the character encoding to be used for names and values before percent-encoding.
sourcepub fn append_pair(&mut self, name: &str, value: &str) -> &mut Self
pub fn append_pair(&mut self, name: &str, value: &str) -> &mut Self
Serialize and append a name/value pair.
Panics if called after .finish()
.
sourcepub fn extend_pairs<I, K, V>(&mut self, iter: I) -> &mut Selfwhere
I: IntoIterator,
I::Item: Borrow<(K, V)>,
K: AsRef<str>,
V: AsRef<str>,
pub fn extend_pairs<I, K, V>(&mut self, iter: I) -> &mut Selfwhere
I: IntoIterator,
I::Item: Borrow<(K, V)>,
K: AsRef<str>,
V: AsRef<str>,
Serialize and append a number of name/value pairs.
This simply calls append_pair
repeatedly.
This can be more convenient, so the user doesn’t need to introduce a block
to limit the scope of Serializer
’s borrow of its string.
Panics if called after .finish()
.
sourcepub fn append_charset(&mut self) -> &mut Self
pub fn append_charset(&mut self) -> &mut Self
Add a name/value pair whose name is _charset_
and whose value is the character encoding’s name.
(See the encoding_override()
method.)
Panics if called after .finish()
.
sourcepub fn finish(&mut self) -> T::Finished
pub fn finish(&mut self) -> T::Finished
If this serializer was constructed with a string, take and return that string.
use url::form_urlencoded;
let encoded: String = form_urlencoded::Serializer::new(String::new())
.append_pair("foo", "bar & baz")
.append_pair("saison", "Été+hiver")
.finish();
assert_eq!(encoded, "foo=bar+%26+baz&saison=%C3%89t%C3%A9%2Bhiver");
Panics if called more than once.