pub struct DuplicateQS<'a> { /* private fields */ }
Expand description
A querystring parser with support for vectors/lists of values by repeating keys.
§Note
Keys are decoded when calling the parse
method, but values are lazily decoded when you
call the value
method for their keys.
§Example
use serde_querystring::DuplicateQS;
let slice = b"foo=bar&foo=baz&foo&foo=";
let parser = DuplicateQS::parse(slice);
// `values` method returns ALL the values as a vector.
assert_eq!(
parser.values(b"foo"),
Some(vec![
Some("bar".as_bytes().into()),
Some("baz".as_bytes().into()),
None,
Some("".as_bytes().into())
])
);
// `value` method returns the last seen value
assert_eq!(parser.value(b"foo"), Some(Some("".as_bytes().into())));
Implementations§
Source§impl<'a> DuplicateQS<'a>
impl<'a> DuplicateQS<'a>
Sourcepub fn deserialize<T: Deserialize<'a>>(self) -> Result<T, Error>
pub fn deserialize<T: Deserialize<'a>>(self) -> Result<T, Error>
Deserialize the parsed slice into T
Source§impl<'a> DuplicateQS<'a>
impl<'a> DuplicateQS<'a>
Sourcepub fn keys(&self) -> Vec<&Cow<'a, [u8]>>
pub fn keys(&self) -> Vec<&Cow<'a, [u8]>>
Returns a vector containing all the keys in querystring.
Sourcepub fn values(&self, key: &'a [u8]) -> Option<Vec<Option<Cow<'a, [u8]>>>>
pub fn values(&self, key: &'a [u8]) -> Option<Vec<Option<Cow<'a, [u8]>>>>
Returns a vector containing all the values assigned to a key.
It returns None if the key doesn’t exist in the querystring,
the resulting vector may contain None if the key had assignments without a value, ex &key&
§Note
Percent decoding the value is done on-the-fly every time this function is called.
Sourcepub fn value(&self, key: &'a [u8]) -> Option<Option<Cow<'a, [u8]>>>
pub fn value(&self, key: &'a [u8]) -> Option<Option<Cow<'a, [u8]>>>
Returns the last value assigned to a key.
It returns None
if the key doesn’t exist in the querystring,
and returns Some(None)
if the last assignment to a key doesn’t have a value, ex "&key&"
§Note
Percent decoding the value is done on-the-fly every time this function is called.