Serialize a vec with serde_urlencoded
โ Rust ๐ 2026-02-13 ๐ค surdeus ๐๏ธ 1Hi,
I try do send an http request with the reqwest crate. This request need query parameters so I build them with a struct. Reqwest serialize the struct with the help of serde_urlencoded. But this serializer doesnโt support Vectors. Is there a way to tell serde to use a custom function to serialize a Vec ?
#[derive(Debug, Serialize)]
pub enum Direction {
Ascending,
Descending,
}
#[derive(Debug, Serialize)]
pub struct Query {
pub foo: Option<bool>,
pub bar: Vec<Direction>,
}
fn build_request() -> RequestBuilder {
let query = Query {
foo: Some(true),
bar: vec![Direction::Ascending, Direction::Descending],
};
Client::builder().build()?
.get("/baz")
.query(&query)
}
query struct should be serialized to "?foo=true&bar=Ascending,Descending
3 posts - 2 participants
๐ท๏ธ Rust_feed