Created
September 22, 2018 12:15
-
-
Save theredfish/a104834468e097392444e89f1859f2ee to your computer and use it in GitHub Desktop.
Example of serde_qs with an array of form parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(¶ms).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