#query-string #url #serde #hash-map #generic #wrapper #transformation

query_map

VectorMap is a generic wrapper around HashMap<String, Vec<String>> to handle different transformations like URL query strings

7 releases (breaking)

0.7.0 Jul 15, 2023
0.6.0 May 5, 2022
0.5.0 May 4, 2022
0.4.0 Feb 18, 2022
0.1.0 Feb 15, 2022

#158 in Encoding

Download history 10009/week @ 2023-12-23 16076/week @ 2023-12-30 20703/week @ 2024-01-06 20214/week @ 2024-01-13 26024/week @ 2024-01-20 27081/week @ 2024-01-27 23714/week @ 2024-02-03 28285/week @ 2024-02-10 26201/week @ 2024-02-17 27173/week @ 2024-02-24 29032/week @ 2024-03-02 31711/week @ 2024-03-09 30451/week @ 2024-03-16 28224/week @ 2024-03-23 29678/week @ 2024-03-30 23717/week @ 2024-04-06

118,238 downloads per month
Used in 27 crates (4 directly)

MIT license

29KB
704 lines

QueryMap

crates.io Documentation Build Status

QueryMap is a generic wrapper around HashMap<String, Vec> to handle different transformations like URL query strings.

QueryMap can normalize HashMap structures with single value elements into structures with value vector elements.

Installation

cargo install query_map

Examples

Create a QueryMap from a HashMap:

use std::collections::HashMap;
use query_map::QueryMap;

let mut data = HashMap::new();
data.insert("foo".into(), vec!["bar".into()]);

let map: QueryMap = QueryMap::from(data);
assert_eq!("bar", map.first("foo").unwrap());
assert_eq!(None, map.first("bar"));

Create a QueryMap from a Serde Value (requires serde feature):

use query_map::QueryMap;
#[derive(Deserialize)]
struct Test {
    data: QueryMap,
}

let json = serde_json::json!({
    "data": {
        "foo": "bar"
    }
});

let test: Test = serde_json::from_value(json).unwrap();
assert_eq!("bar", test.data.first("foo").unwrap());

Create a QueryMap from a query string (requires url-query feature):

use query_map::QueryMap;

let data = "foo=bar&baz=quux&foo=qux";
let map = data.parse::<QueryMap>().unwrap();
let got = map.all("foo").unwrap();
assert_eq!(vec!["bar", "qux"], got);

Dependencies

~185KB