summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSam Scott <sam.scott89@gmail.com>2019-01-21 11:01:30 -0500
committerSam Scott <sam.scott89@gmail.com>2019-01-21 11:01:30 -0500
commitfcf9feeb0e562ac82ce7c2929cd0db7b0ef0d4a4 (patch)
treede467aaea090ed1416e135d99f79bb5ff1afef45 /examples
parent2e5f3769a8614248ae42f408dee40bbeeed1f615 (diff)
parent51b9edc66b0320e4ad8680416f040070c2b3810c (diff)
Merge branch 'master' of github.com:samscott89/serde_qs
Diffstat (limited to 'examples')
-rw-r--r--examples/introduction.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/examples/introduction.rs b/examples/introduction.rs
index d980719..a1f6fc9 100644
--- a/examples/introduction.rs
+++ b/examples/introduction.rs
@@ -7,6 +7,8 @@ extern crate serde_urlencoded as urlencoded;
use rand::Rng;
use std::collections::HashMap;
+use qs::Config;
+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
struct Address {
city: String,
@@ -64,9 +66,15 @@ fn main() {
// as a list of pairs using serde_urlencoded:
let pairs: Vec<(String, String)> = urlencoded::from_str(&encoded).unwrap();
println!("`serde_urlencoded` from_str to pairs:\n\t{:?}", pairs);
+
// However, the best way is to use serde_qs to deserialize the entire thing
// into a struct:
- let params: QueryParams = qs::from_str(&encoded).unwrap();
+ //
+ // (For this round trip to work, it's necessary to parse the query string
+ // in non-strict mode, to allow parsing of url_encoded square brackets
+ // in the key. See the lib.rs documentation for why).
+ let qs_non_strict = Config::new(5, false);
+ let params: QueryParams = qs_non_strict.deserialize_str(&encoded).unwrap();
assert_eq!(params, example_params);
println!("`serde_qs` from_str to struct:\n\t{:?}", params);