Skip to content

Instantly share code, notes, and snippets.

@theredfish
Created September 22, 2018 12:15
Show Gist options
  • Save theredfish/a104834468e097392444e89f1859f2ee to your computer and use it in GitHub Desktop.
Save theredfish/a104834468e097392444e89f1859f2ee to your computer and use it in GitHub Desktop.
Example of serde_qs with an array of form parameters
extern crate serde_qs as qs;
#[macro_use] extern crate serde_json;
#[macro_use] extern crate serde_derive;
#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct Person {
pub firstname: String,
pub lastname: String,
pub checkboxes: Vec<u32>,
}
pub fn main() {
let params = String::from("firstname=a&lastname=b&checkboxes[]=1&checkboxes[]=2");
let expected_person = Person {
firstname: String::from("a"),
lastname: String::from("b"),
checkboxes: vec![1,2]
};
let input: Person = qs::from_str(&params).unwrap();
assert_eq!(expected_person, input);
println!("{:?}", input);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment