Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calavera/query-map-rs
https://github.com/calavera/query-map-rs
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/calavera/query-map-rs
- Owner: calavera
- License: mit
- Created: 2022-02-15T03:47:24.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-03T15:31:18.000Z (about 1 year ago)
- Last Synced: 2024-04-25T01:42:08.007Z (8 months ago)
- Language: Rust
- Size: 37.1 KB
- Stars: 1
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QueryMap
[![crates.io][crate-image]][crate-link]
[![Documentation][doc-image]][doc-link]
[![Build Status][build-image]][build-link]QueryMap is a generic wrapper around HashMap>
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:
```rust
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):
```rust
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):
```rust
use query_map::QueryMap;let data = "foo=bar&baz=quux&foo=qux";
let map = data.parse::().unwrap();
let got = map.all("foo").unwrap();
assert_eq!(vec!["bar", "qux"], got);
```[//]: # (badges)
[crate-image]: https://img.shields.io/crates/v/query_map.svg
[crate-link]: https://crates.io/crates/query_map
[doc-image]: https://docs.rs/query_map/badge.svg
[doc-link]: https://docs.rs/query_map
[build-image]: https://github.com/calavera/query-map-rs/workflows/Build/badge.svg
[build-link]: https://github.com/calavera/query-map-rs/actions?query=workflow%3ACI+branch%3Amain