Struct serde_qs::Config

source ·
pub struct Config { /* private fields */ }
Expand description

To override the default serialization parameters, first construct a new Config.

The strict parameter controls whether the deserializer will tolerate encoded brackets as part of the key. For example, serializing the field a = vec![12] might give a[0]=12. In strict mode, the only string accepted will be this string, whereas in non-strict mode, this can also be deserialized from a%5B0%5D=12. Strict mode is more accurate for cases where it a field may contain square brackets. In non-strict mode, the deserializer will generally tolerate unexpected characters.

A max_depth of 0 implies no nesting: the result will be a flat map. This is mostly useful when the maximum nested depth is known beforehand, to prevent denial of service attacks by providing incredibly deeply nested inputs.

The default value for max_depth is 5, and the default mode is strict=true.

use serde_qs::Config;
use std::collections::HashMap;

let config = Config::new(0, true);
let map: HashMap<String, String> = config.deserialize_str("a[b][c]=1")
                                         .unwrap();
assert_eq!(map.get("a[b][c]").unwrap(), "1");

let config = Config::new(10, true);
let map: HashMap<String, HashMap<String, HashMap<String, String>>> =
            config.deserialize_str("a[b][c]=1").unwrap();
assert_eq!(map.get("a").unwrap().get("b").unwrap().get("c").unwrap(), "1");

Implementations§

source§

impl Config

source

pub fn new(max_depth: usize, strict: bool) -> Self

Create a new Config with the specified max_depth and strict mode.

source§

impl Config

source

pub fn deserialize_bytes<'de, T: Deserialize<'de>>( &self, input: &'de [u8] ) -> Result<T, Error>

Deserializes a querystring from a &[u8] using this Config.

source

pub fn deserialize_str<'de, T: Deserialize<'de>>( &self, input: &'de str ) -> Result<T, Error>

Deserializes a querystring from a &str using this Config.

Trait Implementations§

source§

impl Clone for Config

source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Config

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Copy for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more