form_urlencoded

Struct Serializer

Source
pub struct Serializer<'a, T: Target> { /* private fields */ }
Expand description

Implementations§

Source§

impl<'a, T: Target> Serializer<'a, T>

Source

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.

Source

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.

Source

pub fn clear(&mut self) -> &mut Self

Remove any existing name/value pair.

Panics if called after .finish().

Source

pub fn encoding_override(&mut self, new: EncodingOverride<'a>) -> &mut Self

Set the character encoding to be used for names and values before percent-encoding.

Source

pub fn append_pair(&mut self, name: &str, value: &str) -> &mut Self

Serialize and append a name/value pair.

Panics if called after .finish().

Source

pub fn append_key_only(&mut self, name: &str) -> &mut Self

Serialize and append a name of parameter without any value.

Panics if called after .finish().

Source

pub fn extend_pairs<I, K, V>(&mut self, iter: I) -> &mut Self
where 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().

Source

pub fn extend_keys_only<I, K>(&mut self, iter: I) -> &mut Self
where I: IntoIterator, I::Item: Borrow<K>, K: AsRef<str>,

Serialize and append a number of names without values.

This simply calls append_key_only 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().

Source

pub fn finish(&mut self) -> T::Finished

If this serializer was constructed with a string, take and return that string.

use 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.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Serializer<'a, T>
where T: Freeze,

§

impl<'a, T> !RefUnwindSafe for Serializer<'a, T>

§

impl<'a, T> !Send for Serializer<'a, T>

§

impl<'a, T> !Sync for Serializer<'a, T>

§

impl<'a, T> Unpin for Serializer<'a, T>
where T: Unpin,

§

impl<'a, T> !UnwindSafe for Serializer<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.