std.querystring
Types
struct QsError
Functions
Parse a JSON into specific type.
Parse a JSON into specific type.
Parse a JSON into specific type.
nv
use std.querystring;
struct User {
name: string,
id: int,
profile: Profile?,
tags: [string]
}
struct Profile {
city: string?
}
let user = try! querystring.parse::<User>(`name=Jason+Lee&id=123456&profile[city]=Chengdu&tags[]=Rust&tags[]=Navi`);
assert_eq user.name, "Jason Lee";
assert_eq user.id, 123456;
assert_eq user.profile?.city, "Chengdu";
assert_eq user.tags.len(), 2;
assert_eq user.tags[0], "Rust";
assert_eq user.tags[1], "Navi";
Serialize the given value as query string.
Serialize the given value as query string.
Serialize the given value as query string.
nv
use std.querystring;
struct User {
name: string,
id: int,
profile: Profile,
tags: [string]
}
struct Profile {
city: string?
}
let user = User {
name: "Jason Lee",
id: 123456,
profile: {
city: "Chengdu"
},
tags: ["Rust", "Navi"]
};
assert_eq try! querystring.to_string(user), "name=Jason+Lee&id=123456&profile[city]=Chengdu&tags[0]=Rust&tags[1]=Navi";