Struct serde_querystring::DelimiterQS
source · pub struct DelimiterQS<'a> { /* private fields */ }
Expand description
A querystring parser with support for vectors/lists of values by the use of a delimiter(ex: |
).
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::DelimiterQS;
let slice = b"foo=bar|baz||";
let parser = DelimiterQS::parse(slice, b'|');
// `values` method returns ALL the values as a vector.
assert_eq!(
parser.values(b"foo"),
Some(Some(vec![
"bar".as_bytes().into(),
"baz".as_bytes().into(),
"".as_bytes().into(),
"".as_bytes().into()
]))
);
// `value` method returns the whole slice as the value without parsing by delimiter.
assert_eq!(parser.value(b"foo"), Some(Some("bar|baz||".as_bytes().into())));
Implementations§
source§impl<'a> DelimiterQS<'a>
impl<'a> DelimiterQS<'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> DelimiterQS<'a>
impl<'a> DelimiterQS<'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<Option<Vec<Cow<'a, [u8]>>>>
pub fn values(&self, key: &'a [u8]) -> Option<Option<Vec<Cow<'a, [u8]>>>>
Returns the values assigned to a key(only the last assignment) parsed using delimiter.
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.
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 without taking delimiters into account
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.