mirror of https://github.com/fafhrd91/actix-web
Move serde_urlencoded to src/
This commit is contained in:
parent
09efa6aeb2
commit
e8b3c303b7
|
@ -68,7 +68,6 @@ rand = "0.5"
|
|||
regex = "1.0"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_urlencoded = { path = "./serde_urlencoded/" }
|
||||
sha1 = "0.6"
|
||||
smallvec = "0.6"
|
||||
time = "0.1"
|
||||
|
@ -104,6 +103,10 @@ tokio-tls = { version="0.1", optional = true }
|
|||
openssl = { version="0.10", optional = true }
|
||||
tokio-openssl = { version="0.2", optional = true }
|
||||
|
||||
# forked url_encoded
|
||||
itoa = "0.4"
|
||||
dtoa = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.5"
|
||||
serde_derive = "1.0"
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
[package]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.5.2"
|
||||
authors = ["Anthony Ramine <n.oxyde@gmail.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/nox/serde_urlencoded"
|
||||
documentation = "https://docs.rs/serde_urlencoded"
|
||||
description = "`x-www-form-urlencoded` meets Serde"
|
||||
categories = ["encoding", "web-programming"]
|
||||
keywords = ["serde", "serialization", "urlencoded"]
|
||||
|
||||
[badges]
|
||||
travis-ci = {repository = "nox/serde_urlencoded"}
|
||||
|
||||
[lib]
|
||||
test = false
|
||||
|
||||
[dependencies]
|
||||
dtoa = "0.4.0"
|
||||
itoa = "0.4.0"
|
||||
serde = "1.0.0"
|
||||
url = "1.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
serde_derive = "1.0"
|
|
@ -1,176 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
|
@ -1,25 +0,0 @@
|
|||
Copyright (c) 2016 Anthony Ramine
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
|
@ -1,56 +0,0 @@
|
|||
`x-www-form-urlencoded` meets Serde
|
||||
===================================
|
||||
|
||||
## Fork Note
|
||||
|
||||
This is a local fork for actix-web due to the original repo being unmaintained.
|
||||
|
||||
## README
|
||||
|
||||
This crate is a Rust library for serialising to and deserialising from
|
||||
the [`application/x-www-form-urlencoded`][urlencoded] format. It is built
|
||||
upon [Serde], a high performance generic serialization framework and [rust-url],
|
||||
a URL parser for Rust.
|
||||
|
||||
[rust-url]: https://github.com/servo/rust-url
|
||||
[Serde]: https://github.com/serde-rs/serde
|
||||
[urlencoded]: https://url.spec.whatwg.org/#application/x-www-form-urlencoded
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
This crate works with Cargo and can be found on
|
||||
[crates.io] with a `Cargo.toml` like:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
serde_urlencoded = "0.5.1"
|
||||
```
|
||||
|
||||
[crates.io]: https://crates.io/crates/serde_urlencoded
|
||||
|
||||
## Getting help
|
||||
|
||||
Serde developers live in the #serde channel on
|
||||
[`irc.mozilla.org`](https://wiki.mozilla.org/IRC) and most rust-url developers
|
||||
live in the #servo one. The #rust channel is also a good resource with generally
|
||||
faster response time but less specific knowledge about Serde, rust-url or this
|
||||
crate. If IRC is not your thing, we are happy to respond to [GitHub
|
||||
issues](https://github.com/nox/serde_urlencoded/issues/new) as well.
|
||||
|
||||
## License
|
||||
|
||||
serde_urlencoded is licensed under either of
|
||||
|
||||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||
http://www.apache.org/licenses/LICENSE-2.0)
|
||||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
||||
http://opensource.org/licenses/MIT)
|
||||
|
||||
at your option.
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in serde_urlencoded by you, as defined in the Apache-2.0 license,
|
||||
shall be dual licensed as above, without any additional terms or conditions.
|
|
@ -1,17 +0,0 @@
|
|||
//! `x-www-form-urlencoded` meets Serde
|
||||
|
||||
#![warn(unused_extern_crates)]
|
||||
|
||||
extern crate itoa;
|
||||
extern crate dtoa;
|
||||
#[macro_use]
|
||||
extern crate serde;
|
||||
extern crate url;
|
||||
|
||||
pub mod de;
|
||||
pub mod ser;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use de::{Deserializer, from_bytes, from_reader, from_str};
|
||||
#[doc(inline)]
|
||||
pub use ser::{Serializer, to_string};
|
|
@ -1,62 +0,0 @@
|
|||
extern crate serde_urlencoded;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[test]
|
||||
fn deserialize_bytes() {
|
||||
let result = vec![("first".to_owned(), 23), ("last".to_owned(), 42)];
|
||||
|
||||
assert_eq!(serde_urlencoded::from_bytes(b"first=23&last=42"),
|
||||
Ok(result));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_str() {
|
||||
let result = vec![("first".to_owned(), 23), ("last".to_owned(), 42)];
|
||||
|
||||
assert_eq!(serde_urlencoded::from_str("first=23&last=42"),
|
||||
Ok(result));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_reader() {
|
||||
let result = vec![("first".to_owned(), 23), ("last".to_owned(), 42)];
|
||||
|
||||
assert_eq!(serde_urlencoded::from_reader(b"first=23&last=42" as &[_]),
|
||||
Ok(result));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_option() {
|
||||
let result = vec![
|
||||
("first".to_owned(), Some(23)),
|
||||
("last".to_owned(), Some(42)),
|
||||
];
|
||||
assert_eq!(serde_urlencoded::from_str("first=23&last=42"), Ok(result));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_unit() {
|
||||
assert_eq!(serde_urlencoded::from_str(""), Ok(()));
|
||||
assert_eq!(serde_urlencoded::from_str("&"), Ok(()));
|
||||
assert_eq!(serde_urlencoded::from_str("&&"), Ok(()));
|
||||
assert!(serde_urlencoded::from_str::<()>("first=23").is_err());
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq, Eq)]
|
||||
enum X {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_unit_enum() {
|
||||
let result = vec![
|
||||
("one".to_owned(), X::A),
|
||||
("two".to_owned(), X::B),
|
||||
("three".to_owned(), X::C)
|
||||
];
|
||||
|
||||
assert_eq!(serde_urlencoded::from_str("one=A&two=B&three=C"), Ok(result));
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
extern crate serde_urlencoded;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[test]
|
||||
fn serialize_option_map_int() {
|
||||
let params = &[("first", Some(23)), ("middle", None), ("last", Some(42))];
|
||||
|
||||
assert_eq!(serde_urlencoded::to_string(params),
|
||||
Ok("first=23&last=42".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_option_map_string() {
|
||||
let params =
|
||||
&[("first", Some("hello")), ("middle", None), ("last", Some("world"))];
|
||||
|
||||
assert_eq!(serde_urlencoded::to_string(params),
|
||||
Ok("first=hello&last=world".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_option_map_bool() {
|
||||
let params = &[("one", Some(true)), ("two", Some(false))];
|
||||
|
||||
assert_eq!(serde_urlencoded::to_string(params),
|
||||
Ok("one=true&two=false".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_map_bool() {
|
||||
let params = &[("one", true), ("two", false)];
|
||||
|
||||
assert_eq!(serde_urlencoded::to_string(params),
|
||||
Ok("one=true&two=false".to_owned()));
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
enum X {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_unit_enum() {
|
||||
let params = &[("one", X::A), ("two", X::B), ("three", X::C)];
|
||||
assert_eq!(serde_urlencoded::to_string(params),
|
||||
Ok("one=A&two=B&three=C".to_owned()));
|
||||
}
|
|
@ -133,7 +133,6 @@ extern crate num_cpus;
|
|||
#[macro_use]
|
||||
extern crate percent_encoding;
|
||||
extern crate serde_json;
|
||||
extern crate serde_urlencoded;
|
||||
extern crate smallvec;
|
||||
#[macro_use]
|
||||
extern crate actix as actix_inner;
|
||||
|
@ -152,6 +151,7 @@ extern crate openssl;
|
|||
#[cfg(feature = "openssl")]
|
||||
extern crate tokio_openssl;
|
||||
|
||||
mod serde_urlencoded;
|
||||
mod application;
|
||||
mod body;
|
||||
mod context;
|
||||
|
|
|
@ -14,7 +14,7 @@ pub use serde::de::value::Error;
|
|||
|
||||
/// Deserializes a `application/x-wwww-url-encoded` value from a `&[u8]`.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// let meal = vec![
|
||||
/// ("bread".to_owned(), "baguette".to_owned()),
|
||||
/// ("cheese".to_owned(), "comté".to_owned()),
|
||||
|
@ -35,7 +35,7 @@ pub fn from_bytes<'de, T>(input: &'de [u8]) -> Result<T, Error>
|
|||
|
||||
/// Deserializes a `application/x-wwww-url-encoded` value from a `&str`.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// let meal = vec![
|
||||
/// ("bread".to_owned(), "baguette".to_owned()),
|
||||
/// ("cheese".to_owned(), "comté".to_owned()),
|
||||
|
@ -54,6 +54,7 @@ pub fn from_str<'de, T>(input: &'de str) -> Result<T, Error>
|
|||
from_bytes(input.as_bytes())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Convenience function that reads all bytes from `reader` and deserializes
|
||||
/// them with `from_bytes`.
|
||||
pub fn from_reader<T, R>(mut reader: R) -> Result<T, Error>
|
|
@ -0,0 +1,114 @@
|
|||
//! `x-www-form-urlencoded` meets Serde
|
||||
|
||||
extern crate itoa;
|
||||
extern crate dtoa;
|
||||
|
||||
pub mod de;
|
||||
pub mod ser;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use self::de::{Deserializer, from_bytes, from_reader, from_str};
|
||||
#[doc(inline)]
|
||||
pub use self::ser::{Serializer, to_string};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn deserialize_bytes() {
|
||||
let result = vec![("first".to_owned(), 23), ("last".to_owned(), 42)];
|
||||
|
||||
assert_eq!(super::from_bytes(b"first=23&last=42"),
|
||||
Ok(result));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_str() {
|
||||
let result = vec![("first".to_owned(), 23), ("last".to_owned(), 42)];
|
||||
|
||||
assert_eq!(super::from_str("first=23&last=42"),
|
||||
Ok(result));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_reader() {
|
||||
let result = vec![("first".to_owned(), 23), ("last".to_owned(), 42)];
|
||||
|
||||
assert_eq!(super::from_reader(b"first=23&last=42" as &[_]),
|
||||
Ok(result));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_option() {
|
||||
let result = vec![
|
||||
("first".to_owned(), Some(23)),
|
||||
("last".to_owned(), Some(42)),
|
||||
];
|
||||
assert_eq!(super::from_str("first=23&last=42"), Ok(result));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_unit() {
|
||||
assert_eq!(super::from_str(""), Ok(()));
|
||||
assert_eq!(super::from_str("&"), Ok(()));
|
||||
assert_eq!(super::from_str("&&"), Ok(()));
|
||||
assert!(super::from_str::<()>("first=23").is_err());
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
|
||||
enum X {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_unit_enum() {
|
||||
let result = vec![
|
||||
("one".to_owned(), X::A),
|
||||
("two".to_owned(), X::B),
|
||||
("three".to_owned(), X::C)
|
||||
];
|
||||
|
||||
assert_eq!(super::from_str("one=A&two=B&three=C"), Ok(result));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_option_map_int() {
|
||||
let params = &[("first", Some(23)), ("middle", None), ("last", Some(42))];
|
||||
|
||||
assert_eq!(super::to_string(params),
|
||||
Ok("first=23&last=42".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_option_map_string() {
|
||||
let params =
|
||||
&[("first", Some("hello")), ("middle", None), ("last", Some("world"))];
|
||||
|
||||
assert_eq!(super::to_string(params),
|
||||
Ok("first=hello&last=world".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_option_map_bool() {
|
||||
let params = &[("one", Some(true)), ("two", Some(false))];
|
||||
|
||||
assert_eq!(super::to_string(params),
|
||||
Ok("one=true&two=false".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_map_bool() {
|
||||
let params = &[("one", true), ("two", false)];
|
||||
|
||||
assert_eq!(super::to_string(params),
|
||||
Ok("one=true&two=false".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_unit_enum() {
|
||||
let params = &[("one", X::A), ("two", X::B), ("three", X::C)];
|
||||
assert_eq!(super::to_string(params),
|
||||
Ok("one=A&two=B&three=C".to_owned()));
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use ser::Error;
|
||||
use ser::part::Sink;
|
||||
use super::super::ser::Error;
|
||||
use super::super::ser::part::Sink;
|
||||
use serde::Serialize;
|
||||
use std::borrow::Cow;
|
||||
use std::ops::Deref;
|
|
@ -15,7 +15,7 @@ use url::form_urlencoded::Target as UrlEncodedTarget;
|
|||
|
||||
/// Serializes a value into a `application/x-wwww-url-encoded` `String` buffer.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// let meal = &[
|
||||
/// ("bread", "baguette"),
|
||||
/// ("cheese", "comté"),
|
|
@ -1,7 +1,7 @@
|
|||
use ser::Error;
|
||||
use ser::key::KeySink;
|
||||
use ser::part::PartSerializer;
|
||||
use ser::value::ValueSink;
|
||||
use super::super::ser::Error;
|
||||
use super::super::ser::key::KeySink;
|
||||
use super::super::ser::part::PartSerializer;
|
||||
use super::super::ser::value::ValueSink;
|
||||
use serde::ser;
|
||||
use std::borrow::Cow;
|
||||
use std::mem;
|
|
@ -1,7 +1,8 @@
|
|||
use dtoa;
|
||||
use itoa;
|
||||
use ser::Error;
|
||||
use serde::ser;
|
||||
use ::serde;
|
||||
|
||||
use super::super::dtoa;
|
||||
use super::super::itoa;
|
||||
use super::super::ser::Error;
|
||||
use std::str;
|
||||
|
||||
pub struct PartSerializer<S> {
|
||||
|
@ -25,7 +26,7 @@ pub trait Sink: Sized {
|
|||
fn serialize_string(self, value: String) -> Result<Self::Ok, Error>;
|
||||
fn serialize_none(self) -> Result<Self::Ok, Error>;
|
||||
|
||||
fn serialize_some<T: ?Sized + ser::Serialize>
|
||||
fn serialize_some<T: ?Sized + serde::ser::Serialize>
|
||||
(self,
|
||||
value: &T)
|
||||
-> Result<Self::Ok, Error>;
|
||||
|
@ -33,16 +34,16 @@ pub trait Sink: Sized {
|
|||
fn unsupported(self) -> Error;
|
||||
}
|
||||
|
||||
impl<S: Sink> ser::Serializer for PartSerializer<S> {
|
||||
impl<S: Sink> serde::ser::Serializer for PartSerializer<S> {
|
||||
type Ok = S::Ok;
|
||||
type Error = Error;
|
||||
type SerializeSeq = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeTuple = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeTupleStruct = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeTupleVariant = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeMap = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeStruct = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeStructVariant = ser::Impossible<S::Ok, Error>;
|
||||
type SerializeSeq = serde::ser::Impossible<S::Ok, Error>;
|
||||
type SerializeTuple = serde::ser::Impossible<S::Ok, Error>;
|
||||
type SerializeTupleStruct = serde::ser::Impossible<S::Ok, Error>;
|
||||
type SerializeTupleVariant = serde::ser::Impossible<S::Ok, Error>;
|
||||
type SerializeMap = serde::ser::Impossible<S::Ok, Error>;
|
||||
type SerializeStruct = serde::ser::Impossible<S::Ok, Error>;
|
||||
type SerializeStructVariant = serde::ser::Impossible<S::Ok, Error>;
|
||||
|
||||
fn serialize_bool(self, v: bool) -> Result<S::Ok, Error> {
|
||||
self.sink.serialize_static_str(if v { "true" } else { "false" })
|
||||
|
@ -119,7 +120,7 @@ impl<S: Sink> ser::Serializer for PartSerializer<S> {
|
|||
self.sink.serialize_static_str(variant.into())
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct<T: ?Sized + ser::Serialize>
|
||||
fn serialize_newtype_struct<T: ?Sized + serde::ser::Serialize>
|
||||
(self,
|
||||
_name: &'static str,
|
||||
value: &T)
|
||||
|
@ -127,7 +128,7 @@ impl<S: Sink> ser::Serializer for PartSerializer<S> {
|
|||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T: ?Sized + ser::Serialize>
|
||||
fn serialize_newtype_variant<T: ?Sized + serde::ser::Serialize>
|
||||
(self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
|
@ -141,7 +142,7 @@ impl<S: Sink> ser::Serializer for PartSerializer<S> {
|
|||
self.sink.serialize_none()
|
||||
}
|
||||
|
||||
fn serialize_some<T: ?Sized + ser::Serialize>(self,
|
||||
fn serialize_some<T: ?Sized + serde::ser::Serialize>(self,
|
||||
value: &T)
|
||||
-> Result<S::Ok, Error> {
|
||||
self.sink.serialize_some(value)
|
||||
|
@ -207,7 +208,7 @@ impl<S: Sink> PartSerializer<S> {
|
|||
let mut buf = [b'\0'; 20];
|
||||
let len = itoa::write(&mut buf[..], value).unwrap();
|
||||
let part = unsafe { str::from_utf8_unchecked(&buf[0..len]) };
|
||||
ser::Serializer::serialize_str(self, part)
|
||||
serde::ser::Serializer::serialize_str(self, part)
|
||||
}
|
||||
|
||||
fn serialize_floating<F>(self, value: F) -> Result<S::Ok, Error>
|
||||
|
@ -216,6 +217,6 @@ impl<S: Sink> PartSerializer<S> {
|
|||
let mut buf = [b'\0'; 24];
|
||||
let len = dtoa::write(&mut buf[..], value).unwrap();
|
||||
let part = unsafe { str::from_utf8_unchecked(&buf[0..len]) };
|
||||
ser::Serializer::serialize_str(self, part)
|
||||
serde::ser::Serializer::serialize_str(self, part)
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use ser::Error;
|
||||
use ser::part::{PartSerializer, Sink};
|
||||
use super::super::ser::Error;
|
||||
use super::super::ser::part::{PartSerializer, Sink};
|
||||
use serde::ser::Serialize;
|
||||
use std::str;
|
||||
use url::form_urlencoded::Serializer as UrlEncodedSerializer;
|
Loading…
Reference in New Issue