Crates.io | yaup |
lib.rs | yaup |
version | 0.3.1 |
source | src |
created_at | 2022-06-21 17:55:50.959096 |
updated_at | 2024-06-10 10:06:36.645845 |
description | URL parameters serialization |
homepage | |
repository | https://github.com/meilisearch/yaup |
max_upload_size | |
id | 610408 |
size | 45,314 |
Serialize your structures as query parameters. I made this crate because I didn't find anything that matched the structure of the query parameters used in Meilisearch.
Specificities of this query parameters format:
?
if there are parameters to send.HashMap
, BTreeMap
, etc.{ doggo: vec!["kefir", "echo"] }
serialize as ?doggo=kefir,echo
.null
values are not ignored. { doggo: Vec::new(), catto: None }
serialize as ?doggo=&catto=null
.HashMap
for example).#[derive(Debug, serde::Serialize)]
enum Filter { New, Registered, Blocked }
#[derive(Debug, serde::Serialize)]
struct Params {
cursor: Option<usize>,
per_page: Option<usize>,
username: String,
filter: Vec<Filter>,
}
let params = Params {
cursor: Some(42),
per_page: None,
username: String::from("tamo"),
filter: vec![Filter::New, Filter::Blocked],
};
assert_eq!(
yaup::to_string(¶ms).unwrap(),
"?cursor=42&per_page=null&username=tamo&filter=New,Blocked"
);
This was originally a fork of serde_url_params
which is still maintained.
Thanks, boxdot
, for the initial code.
Everything has been rewritten from scratch for the v0.3.0.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this document by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.