RPM build fix (reverted CI changes which will need to be un-reverted or made conditional) and vendor Rust dependencies to make builds much faster in any CI system.
This commit is contained in:
1
zeroidc/vendor/serde_path_to_error/.cargo-checksum.json
vendored
Normal file
1
zeroidc/vendor/serde_path_to_error/.cargo-checksum.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"files":{"Cargo.toml":"29ceda057ef0e593145c3e4f82bea0fc3938b1cf454d4235a7c1a11ce20016d0","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"84dca3eec4d2d933612659b7cbeb1db61e79321e18e8f562efa6d8257d6094a9","src/de.rs":"c0ab233062d24bd999d6c017d368ae987b18889313962df3b9b581e998693398","src/lib.rs":"69eb52b0a107dce600e1de26cbb5b26f2c92823c63a6dace2fdd785b8ee1169a","src/path.rs":"dcf0f76e280a063fbe07afe31442faa07d9c19150958bde1e75366a22c716f66","src/ser.rs":"093300bd35f0b499a1c28c969a7ef7f8b0ed8fb5ff09ddbfe857dcca31e213f1","src/wrap.rs":"9d88271729c6dc90d16328454f0432e18ce13df6c8dc4749785c5d3c7d260c09","tests/deserialize.rs":"785acf90b3ddc32febc7a87d0af274c59d6876a7ee7181deddf74a9d0516d93f","tests/serialize.rs":"84a16ce654ce3060a0c1cf23430ad4e5c5a9f7816c84c502716d2c991e90e358"},"package":"d7868ad3b8196a8a0aea99a8220b124278ee5320a55e4fde97794b6f85b1a377"}
|
||||
33
zeroidc/vendor/serde_path_to_error/Cargo.toml
vendored
Normal file
33
zeroidc/vendor/serde_path_to_error/Cargo.toml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
rust-version = "1.31"
|
||||
name = "serde_path_to_error"
|
||||
version = "0.1.7"
|
||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||
description = "Path to the element that failed to deserialize"
|
||||
readme = "README.md"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/dtolnay/path-to-error"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.serde_derive]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.serde_json]
|
||||
version = "1.0"
|
||||
201
zeroidc/vendor/serde_path_to_error/LICENSE-APACHE
vendored
Normal file
201
zeroidc/vendor/serde_path_to_error/LICENSE-APACHE
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
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
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
23
zeroidc/vendor/serde_path_to_error/LICENSE-MIT
vendored
Normal file
23
zeroidc/vendor/serde_path_to_error/LICENSE-MIT
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
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.
|
||||
72
zeroidc/vendor/serde_path_to_error/README.md
vendored
Normal file
72
zeroidc/vendor/serde_path_to_error/README.md
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
# Serde path to error
|
||||
|
||||
[<img alt="github" src="https://img.shields.io/badge/github-dtolnay/path--to--error-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/path-to-error)
|
||||
[<img alt="crates.io" src="https://img.shields.io/crates/v/serde_path_to_error.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/serde_path_to_error)
|
||||
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-serde__path__to__error-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/serde_path_to_error)
|
||||
[<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/path-to-error/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/path-to-error/actions?query=branch%3Amaster)
|
||||
|
||||
Find out the path at which a deserialization error occurred. This crate provides
|
||||
a wrapper that works with any existing Serde `Deserializer` and exposes the
|
||||
chain of field names leading to the error.
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
serde = "1.0"
|
||||
serde_path_to_error = "0.1"
|
||||
```
|
||||
|
||||
```rust
|
||||
use serde::Deserialize;
|
||||
use std::collections::BTreeMap as Map;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Package {
|
||||
name: String,
|
||||
dependencies: Map<String, Dependency>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Dependency {
|
||||
version: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let j = r#"{
|
||||
"name": "demo",
|
||||
"dependencies": {
|
||||
"serde": {
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
|
||||
// Some Deserializer.
|
||||
let jd = &mut serde_json::Deserializer::from_str(j);
|
||||
|
||||
let result: Result<Package, _> = serde_path_to_error::deserialize(jd);
|
||||
match result {
|
||||
Ok(_) => panic!("expected a type error"),
|
||||
Err(err) => {
|
||||
let path = err.path().to_string();
|
||||
assert_eq!(path, "dependencies.serde.version");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
#### License
|
||||
|
||||
<sup>
|
||||
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
|
||||
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
|
||||
</sup>
|
||||
|
||||
<br>
|
||||
|
||||
<sub>
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
|
||||
be dual licensed as above, without any additional terms or conditions.
|
||||
</sub>
|
||||
1532
zeroidc/vendor/serde_path_to_error/src/de.rs
vendored
Normal file
1532
zeroidc/vendor/serde_path_to_error/src/de.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
182
zeroidc/vendor/serde_path_to_error/src/lib.rs
vendored
Normal file
182
zeroidc/vendor/serde_path_to_error/src/lib.rs
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
//! [![github]](https://github.com/dtolnay/path-to-error) [![crates-io]](https://crates.io/crates/serde_path_to_error) [![docs-rs]](https://docs.rs/serde_path_to_error)
|
||||
//!
|
||||
//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
|
||||
//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
|
||||
//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K
|
||||
//!
|
||||
//! <br>
|
||||
//!
|
||||
//! Find out the path at which a deserialization error occurred. This crate
|
||||
//! provides a wrapper that works with any existing Serde `Deserializer` and
|
||||
//! exposes the chain of field names leading to the error.
|
||||
//!
|
||||
//! # Example
|
||||
//!
|
||||
//! ```
|
||||
//! # use serde_derive::Deserialize;
|
||||
//! #
|
||||
//! use serde::Deserialize;
|
||||
//! use std::collections::BTreeMap as Map;
|
||||
//!
|
||||
//! #[derive(Deserialize)]
|
||||
//! struct Package {
|
||||
//! name: String,
|
||||
//! dependencies: Map<String, Dependency>,
|
||||
//! }
|
||||
//!
|
||||
//! #[derive(Deserialize)]
|
||||
//! struct Dependency {
|
||||
//! version: String,
|
||||
//! }
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let j = r#"{
|
||||
//! "name": "demo",
|
||||
//! "dependencies": {
|
||||
//! "serde": {
|
||||
//! "version": 1
|
||||
//! }
|
||||
//! }
|
||||
//! }"#;
|
||||
//!
|
||||
//! // Some Deserializer.
|
||||
//! let jd = &mut serde_json::Deserializer::from_str(j);
|
||||
//!
|
||||
//! let result: Result<Package, _> = serde_path_to_error::deserialize(jd);
|
||||
//! match result {
|
||||
//! Ok(_) => panic!("expected a type error"),
|
||||
//! Err(err) => {
|
||||
//! let path = err.path().to_string();
|
||||
//! assert_eq!(path, "dependencies.serde.version");
|
||||
//! }
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/serde_path_to_error/0.1.7")]
|
||||
#![allow(
|
||||
clippy::iter_not_returning_iterator, // https://github.com/rust-lang/rust-clippy/issues/8285
|
||||
clippy::missing_errors_doc,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::must_use_candidate,
|
||||
clippy::new_without_default
|
||||
)]
|
||||
|
||||
mod de;
|
||||
mod path;
|
||||
mod ser;
|
||||
mod wrap;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::error::Error as StdError;
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
pub use crate::de::{deserialize, Deserializer};
|
||||
pub use crate::path::{Path, Segment, Segments};
|
||||
pub use crate::ser::{serialize, Serializer};
|
||||
|
||||
/// Original deserializer error together with the path at which it occurred.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Error<E> {
|
||||
path: Path,
|
||||
original: E,
|
||||
}
|
||||
|
||||
impl<E> Error<E> {
|
||||
/// Element path at which this deserialization error occurred.
|
||||
pub fn path(&self) -> &Path {
|
||||
&self.path
|
||||
}
|
||||
|
||||
/// The Deserializer's underlying error that occurred.
|
||||
pub fn into_inner(self) -> E {
|
||||
self.original
|
||||
}
|
||||
|
||||
/// Reference to the Deserializer's underlying error that occurred.
|
||||
pub fn inner(&self) -> &E {
|
||||
&self.original
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Display> Display for Error<E> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}: {}", self.path(), self.inner())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StdError + 'static> StdError for Error<E> {
|
||||
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
||||
Some(self.inner())
|
||||
}
|
||||
}
|
||||
|
||||
/// State for bookkeeping across nested deserializer calls.
|
||||
///
|
||||
/// You don't need this if you are using `serde_path_to_error::deserializer`. If
|
||||
/// you are managing your own `Deserializer`, see the usage example on
|
||||
/// [`Deserializer`].
|
||||
pub struct Track {
|
||||
path: Cell<Option<Path>>,
|
||||
}
|
||||
|
||||
impl Track {
|
||||
/// Empty state with no error having happened yet.
|
||||
pub fn new() -> Self {
|
||||
Track {
|
||||
path: Cell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets path at which the error occurred. Only meaningful after we know
|
||||
/// that an error has occurred. Returns an empty path otherwise.
|
||||
pub fn path(self) -> Path {
|
||||
self.path.into_inner().unwrap_or_else(Path::empty)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn trigger<E>(&self, chain: &Chain, err: E) -> E {
|
||||
self.trigger_impl(chain);
|
||||
err
|
||||
}
|
||||
|
||||
fn trigger_impl(&self, chain: &Chain) {
|
||||
self.path.set(Some(match self.path.take() {
|
||||
Some(already_set) => already_set,
|
||||
None => Path::from_chain(chain),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
enum Chain<'a> {
|
||||
Root,
|
||||
Seq {
|
||||
parent: &'a Chain<'a>,
|
||||
index: usize,
|
||||
},
|
||||
Map {
|
||||
parent: &'a Chain<'a>,
|
||||
key: String,
|
||||
},
|
||||
Struct {
|
||||
parent: &'a Chain<'a>,
|
||||
key: &'static str,
|
||||
},
|
||||
Enum {
|
||||
parent: &'a Chain<'a>,
|
||||
variant: String,
|
||||
},
|
||||
Some {
|
||||
parent: &'a Chain<'a>,
|
||||
},
|
||||
NewtypeStruct {
|
||||
parent: &'a Chain<'a>,
|
||||
},
|
||||
NewtypeVariant {
|
||||
parent: &'a Chain<'a>,
|
||||
},
|
||||
NonStringKey {
|
||||
parent: &'a Chain<'a>,
|
||||
},
|
||||
}
|
||||
129
zeroidc/vendor/serde_path_to_error/src/path.rs
vendored
Normal file
129
zeroidc/vendor/serde_path_to_error/src/path.rs
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
use std::fmt::{self, Display};
|
||||
use std::slice;
|
||||
|
||||
use super::Chain;
|
||||
|
||||
/// Path to the error value in the input, like `dependencies.serde.typo1`.
|
||||
///
|
||||
/// Use `path.to_string()` to get a string representation of the path with
|
||||
/// segments separated by periods, or use `path.iter()` to iterate over
|
||||
/// individual segments of the path.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Path {
|
||||
segments: Vec<Segment>,
|
||||
}
|
||||
|
||||
/// Single segment of a path.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Segment {
|
||||
Seq { index: usize },
|
||||
Map { key: String },
|
||||
Enum { variant: String },
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl Path {
|
||||
/// Returns an iterator with element type [`&Segment`][Segment].
|
||||
pub fn iter(&self) -> Segments {
|
||||
Segments {
|
||||
iter: self.segments.iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a Path {
|
||||
type Item = &'a Segment;
|
||||
type IntoIter = Segments<'a>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator over segments of a path.
|
||||
pub struct Segments<'a> {
|
||||
iter: slice::Iter<'a, Segment>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for Segments<'a> {
|
||||
type Item = &'a Segment;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Path {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.segments.is_empty() {
|
||||
return formatter.write_str(".");
|
||||
}
|
||||
|
||||
let mut separator = "";
|
||||
for segment in self {
|
||||
match segment {
|
||||
Segment::Seq { index } => {
|
||||
write!(formatter, "[{}]", index)?;
|
||||
}
|
||||
Segment::Map { key } | Segment::Enum { variant: key } => {
|
||||
write!(formatter, "{}{}", separator, key)?;
|
||||
}
|
||||
Segment::Unknown => {
|
||||
write!(formatter, "{}?", separator)?;
|
||||
}
|
||||
}
|
||||
separator = ".";
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Path {
|
||||
pub(crate) fn empty() -> Self {
|
||||
Path {
|
||||
segments: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_chain(mut chain: &Chain) -> Self {
|
||||
let mut segments = Vec::new();
|
||||
loop {
|
||||
match chain {
|
||||
Chain::Root => break,
|
||||
Chain::Seq { parent, index } => {
|
||||
segments.push(Segment::Seq { index: *index });
|
||||
chain = parent;
|
||||
}
|
||||
Chain::Map { parent, key } => {
|
||||
segments.push(Segment::Map { key: key.clone() });
|
||||
chain = parent;
|
||||
}
|
||||
Chain::Struct { parent, key } => {
|
||||
let key = *key;
|
||||
segments.push(Segment::Map {
|
||||
key: key.to_owned(),
|
||||
});
|
||||
chain = parent;
|
||||
}
|
||||
Chain::Enum { parent, variant } => {
|
||||
segments.push(Segment::Enum {
|
||||
variant: variant.clone(),
|
||||
});
|
||||
chain = parent;
|
||||
}
|
||||
Chain::Some { parent }
|
||||
| Chain::NewtypeStruct { parent }
|
||||
| Chain::NewtypeVariant { parent } => {
|
||||
chain = parent;
|
||||
}
|
||||
Chain::NonStringKey { parent } => {
|
||||
segments.push(Segment::Unknown);
|
||||
chain = parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
segments.reverse();
|
||||
Path { segments }
|
||||
}
|
||||
}
|
||||
997
zeroidc/vendor/serde_path_to_error/src/ser.rs
vendored
Normal file
997
zeroidc/vendor/serde_path_to_error/src/ser.rs
vendored
Normal file
@@ -0,0 +1,997 @@
|
||||
use crate::wrap::Wrap;
|
||||
use crate::{Chain, Error, Track};
|
||||
use serde::ser::{self, Serialize};
|
||||
use serde::serde_if_integer128;
|
||||
use std::cell::Cell;
|
||||
use std::fmt::Display;
|
||||
|
||||
/// Entry point for tracking path to Serialize error.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use serde_derive::Serialize;
|
||||
/// #
|
||||
/// use serde::Serialize;
|
||||
/// use std::cell::RefCell;
|
||||
///
|
||||
/// #[derive(Serialize)]
|
||||
/// struct Outer<'a> {
|
||||
/// k: Inner<'a>,
|
||||
/// }
|
||||
///
|
||||
/// #[derive(Serialize)]
|
||||
/// struct Inner<'a> {
|
||||
/// refcell: &'a RefCell<String>,
|
||||
/// }
|
||||
///
|
||||
/// let refcell = RefCell::new(String::new());
|
||||
/// let value = Outer {
|
||||
/// k: Inner { refcell: &refcell },
|
||||
/// };
|
||||
///
|
||||
/// // A RefCell cannot be serialized while it is still mutably borrowed.
|
||||
/// let _borrowed = refcell.borrow_mut();
|
||||
///
|
||||
/// // Some Serializer.
|
||||
/// let mut out = Vec::new();
|
||||
/// let jser = &mut serde_json::Serializer::new(&mut out);
|
||||
///
|
||||
/// let result = serde_path_to_error::serialize(&value, jser);
|
||||
/// match result {
|
||||
/// Ok(_) => panic!("expected failure to serialize RefCell"),
|
||||
/// Err(err) => {
|
||||
/// let path = err.path().to_string();
|
||||
/// assert_eq!(path, "k.refcell");
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn serialize<T, S>(value: &T, serializer: S) -> Result<S::Ok, Error<S::Error>>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
S: ser::Serializer,
|
||||
{
|
||||
let mut track = Track::new();
|
||||
match T::serialize(value, Serializer::new(serializer, &mut track)) {
|
||||
Ok(ok) => Ok(ok),
|
||||
Err(err) => Err(Error {
|
||||
path: track.path(),
|
||||
original: err,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// Serializer adapter that records path to serialization errors.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use serde_derive::Serialize;
|
||||
/// #
|
||||
/// use serde::Serialize;
|
||||
/// use std::collections::BTreeMap;
|
||||
///
|
||||
/// // Maps with a non-string key are not valid in JSON.
|
||||
/// let mut inner_map = BTreeMap::new();
|
||||
/// inner_map.insert(vec!['w', 'a', 't'], 0);
|
||||
///
|
||||
/// let mut outer_map = BTreeMap::new();
|
||||
/// outer_map.insert("k", inner_map);
|
||||
///
|
||||
/// // Some Serializer.
|
||||
/// let mut out = Vec::new();
|
||||
/// let jser = &mut serde_json::Serializer::new(&mut out);
|
||||
///
|
||||
/// let mut track = serde_path_to_error::Track::new();
|
||||
/// let ps = serde_path_to_error::Serializer::new(jser, &mut track);
|
||||
///
|
||||
/// match outer_map.serialize(ps) {
|
||||
/// Ok(_) => panic!("expected failure to serialize non-string key"),
|
||||
/// Err(_) => {
|
||||
/// let path = track.path().to_string();
|
||||
/// assert_eq!(path, "k");
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub struct Serializer<'a, 'b, S> {
|
||||
ser: S,
|
||||
chain: &'a Chain<'a>,
|
||||
track: &'b Track,
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> Serializer<'a, 'b, S> {
|
||||
pub fn new(ser: S, track: &'b mut Track) -> Self {
|
||||
Serializer {
|
||||
ser,
|
||||
chain: &Chain::Root,
|
||||
track,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> ser::Serializer for Serializer<'a, 'b, S>
|
||||
where
|
||||
S: ser::Serializer,
|
||||
{
|
||||
type Ok = S::Ok;
|
||||
type Error = S::Error;
|
||||
type SerializeSeq = WrapSeq<'a, 'b, S::SerializeSeq>;
|
||||
type SerializeTuple = WrapSeq<'a, 'b, S::SerializeTuple>;
|
||||
type SerializeTupleStruct = WrapSeq<'a, 'b, S::SerializeTupleStruct>;
|
||||
type SerializeTupleVariant = WrapSeq<'a, 'b, S::SerializeTupleVariant>;
|
||||
type SerializeMap = WrapMap<'a, 'b, S::SerializeMap>;
|
||||
type SerializeStruct = Wrap<'a, 'b, S::SerializeStruct>;
|
||||
type SerializeStructVariant = Wrap<'a, 'b, S::SerializeStructVariant>;
|
||||
|
||||
fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_bool(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_i8(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_i16(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_i32(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_i64(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
serde_if_integer128! {
|
||||
fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_i128(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_u8(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_u16(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_u32(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_u64(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
serde_if_integer128! {
|
||||
fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_u128(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_f32(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_f64(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_char(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_str(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_bytes(v)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_none()
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_some(value)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_unit()
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_unit_struct(name)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_unit_variant(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
variant: &'static str,
|
||||
) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_unit_variant(name, variant_index, variant)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct<T>(
|
||||
self,
|
||||
name: &'static str,
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_newtype_struct(name, value)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T>(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
variant: &'static str,
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.serialize_newtype_variant(name, variant_index, variant, value)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
match self.ser.serialize_seq(len) {
|
||||
Ok(delegate) => Ok(WrapSeq::new(delegate, chain, track)),
|
||||
Err(err) => Err(track.trigger(chain, err)),
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
match self.ser.serialize_tuple(len) {
|
||||
Ok(delegate) => Ok(WrapSeq::new(delegate, chain, track)),
|
||||
Err(err) => Err(track.trigger(chain, err)),
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_tuple_struct(
|
||||
self,
|
||||
name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeTupleStruct, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
match self.ser.serialize_tuple_struct(name, len) {
|
||||
Ok(delegate) => Ok(WrapSeq::new(delegate, chain, track)),
|
||||
Err(err) => Err(track.trigger(chain, err)),
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
variant: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
match self
|
||||
.ser
|
||||
.serialize_tuple_variant(name, variant_index, variant, len)
|
||||
{
|
||||
Ok(delegate) => Ok(WrapSeq::new(delegate, chain, track)),
|
||||
Err(err) => Err(track.trigger(chain, err)),
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
match self.ser.serialize_map(len) {
|
||||
Ok(delegate) => Ok(WrapMap::new(delegate, chain, track)),
|
||||
Err(err) => Err(track.trigger(chain, err)),
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_struct(
|
||||
self,
|
||||
name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeStruct, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
match self.ser.serialize_struct(name, len) {
|
||||
Ok(delegate) => Ok(Wrap::new(delegate, chain, track)),
|
||||
Err(err) => Err(track.trigger(chain, err)),
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_struct_variant(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
variant: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeStructVariant, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
match self
|
||||
.ser
|
||||
.serialize_struct_variant(name, variant_index, variant, len)
|
||||
{
|
||||
Ok(delegate) => Ok(Wrap::new(delegate, chain, track)),
|
||||
Err(err) => Err(track.trigger(chain, err)),
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: ?Sized + Display,
|
||||
{
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.ser
|
||||
.collect_str(value)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn is_human_readable(&self) -> bool {
|
||||
self.ser.is_human_readable()
|
||||
}
|
||||
}
|
||||
|
||||
struct TrackedValue<'a, 'b, X> {
|
||||
value: X,
|
||||
chain: &'a Chain<'a>,
|
||||
track: &'b Track,
|
||||
}
|
||||
|
||||
impl<'a, 'b, X> TrackedValue<'a, 'b, X> {
|
||||
fn new(value: X, chain: &'a Chain<'a>, track: &'b Track) -> Self {
|
||||
TrackedValue {
|
||||
value,
|
||||
chain,
|
||||
track,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, X> Serialize for TrackedValue<'a, 'b, X>
|
||||
where
|
||||
X: Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: ser::Serializer,
|
||||
{
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.value
|
||||
.serialize(Serializer {
|
||||
ser: serializer,
|
||||
chain,
|
||||
track,
|
||||
})
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WrapSeq<'a, 'b, S> {
|
||||
delegate: S,
|
||||
chain: &'a Chain<'a>,
|
||||
index: usize,
|
||||
track: &'b Track,
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> WrapSeq<'a, 'b, S> {
|
||||
fn new(delegate: S, chain: &'a Chain<'a>, track: &'b Track) -> Self {
|
||||
WrapSeq {
|
||||
delegate,
|
||||
chain,
|
||||
index: 0,
|
||||
track,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> ser::SerializeSeq for WrapSeq<'a, 'b, S>
|
||||
where
|
||||
S: ser::SerializeSeq,
|
||||
{
|
||||
type Ok = S::Ok;
|
||||
type Error = S::Error;
|
||||
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let parent = self.chain;
|
||||
let chain = Chain::Seq {
|
||||
parent,
|
||||
index: self.index,
|
||||
};
|
||||
let track = self.track;
|
||||
self.index += 1;
|
||||
self.delegate
|
||||
.serialize_element(&TrackedValue::new(value, &chain, track))
|
||||
.map_err(|err| track.trigger(parent, err))
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.delegate.end().map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> ser::SerializeTuple for WrapSeq<'a, 'b, S>
|
||||
where
|
||||
S: ser::SerializeTuple,
|
||||
{
|
||||
type Ok = S::Ok;
|
||||
type Error = S::Error;
|
||||
|
||||
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let parent = self.chain;
|
||||
let chain = Chain::Seq {
|
||||
parent,
|
||||
index: self.index,
|
||||
};
|
||||
let track = self.track;
|
||||
self.index += 1;
|
||||
self.delegate
|
||||
.serialize_element(&TrackedValue::new(value, &chain, track))
|
||||
.map_err(|err| track.trigger(parent, err))
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.delegate.end().map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> ser::SerializeTupleStruct for WrapSeq<'a, 'b, S>
|
||||
where
|
||||
S: ser::SerializeTupleStruct,
|
||||
{
|
||||
type Ok = S::Ok;
|
||||
type Error = S::Error;
|
||||
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let parent = self.chain;
|
||||
let chain = Chain::Seq {
|
||||
parent,
|
||||
index: self.index,
|
||||
};
|
||||
let track = self.track;
|
||||
self.index += 1;
|
||||
self.delegate
|
||||
.serialize_field(&TrackedValue::new(value, &chain, track))
|
||||
.map_err(|err| track.trigger(parent, err))
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.delegate.end().map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> ser::SerializeTupleVariant for WrapSeq<'a, 'b, S>
|
||||
where
|
||||
S: ser::SerializeTupleVariant,
|
||||
{
|
||||
type Ok = S::Ok;
|
||||
type Error = S::Error;
|
||||
|
||||
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let parent = self.chain;
|
||||
let chain = Chain::Seq {
|
||||
parent,
|
||||
index: self.index,
|
||||
};
|
||||
let track = self.track;
|
||||
self.index += 1;
|
||||
self.delegate
|
||||
.serialize_field(&TrackedValue::new(value, &chain, track))
|
||||
.map_err(|err| track.trigger(parent, err))
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.delegate.end().map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WrapMap<'a, 'b, S> {
|
||||
delegate: S,
|
||||
chain: &'a Chain<'a>,
|
||||
key: Cell<Option<String>>,
|
||||
track: &'b Track,
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> WrapMap<'a, 'b, S> {
|
||||
fn new(delegate: S, chain: &'a Chain<'a>, track: &'b Track) -> Self {
|
||||
WrapMap {
|
||||
delegate,
|
||||
chain,
|
||||
key: Cell::new(None),
|
||||
track,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> ser::SerializeMap for WrapMap<'a, 'b, S>
|
||||
where
|
||||
S: ser::SerializeMap,
|
||||
{
|
||||
type Ok = S::Ok;
|
||||
type Error = S::Error;
|
||||
|
||||
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.key.set(None);
|
||||
self.delegate
|
||||
.serialize_key(&CaptureKey::new(&self.key, key))
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let parent = self.chain;
|
||||
let chain = match self.key.take() {
|
||||
Some(key) => Chain::Map { parent, key },
|
||||
None => Chain::NonStringKey { parent },
|
||||
};
|
||||
let track = self.track;
|
||||
self.delegate
|
||||
.serialize_value(&TrackedValue::new(value, &chain, track))
|
||||
.map_err(|err| track.trigger(parent, err))
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.delegate.end().map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> ser::SerializeStruct for Wrap<'a, 'b, S>
|
||||
where
|
||||
S: ser::SerializeStruct,
|
||||
{
|
||||
type Ok = S::Ok;
|
||||
type Error = S::Error;
|
||||
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let parent = self.chain;
|
||||
let chain = Chain::Struct { parent, key };
|
||||
let track = self.track;
|
||||
self.delegate
|
||||
.serialize_field(key, &TrackedValue::new(value, &chain, track))
|
||||
.map_err(|err| track.trigger(parent, err))
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.delegate.end().map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn skip_field(&mut self, key: &'static str) -> Result<(), Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.delegate
|
||||
.skip_field(key)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, S> ser::SerializeStructVariant for Wrap<'a, 'b, S>
|
||||
where
|
||||
S: ser::SerializeStructVariant,
|
||||
{
|
||||
type Ok = S::Ok;
|
||||
type Error = S::Error;
|
||||
|
||||
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
let parent = self.chain;
|
||||
let chain = Chain::Struct { parent, key };
|
||||
let track = self.track;
|
||||
self.delegate
|
||||
.serialize_field(key, &TrackedValue::new(value, &chain, track))
|
||||
.map_err(|err| track.trigger(parent, err))
|
||||
}
|
||||
|
||||
fn end(self) -> Result<Self::Ok, Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.delegate.end().map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
|
||||
fn skip_field(&mut self, key: &'static str) -> Result<(), Self::Error> {
|
||||
let chain = self.chain;
|
||||
let track = self.track;
|
||||
self.delegate
|
||||
.skip_field(key)
|
||||
.map_err(|err| track.trigger(chain, err))
|
||||
}
|
||||
}
|
||||
|
||||
struct CaptureKey<'a, T> {
|
||||
out: &'a Cell<Option<String>>,
|
||||
delegate: T,
|
||||
}
|
||||
|
||||
impl<'a, T> CaptureKey<'a, T> {
|
||||
fn new(out: &'a Cell<Option<String>>, delegate: T) -> Self {
|
||||
CaptureKey { out, delegate }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Serialize for CaptureKey<'a, T>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: ser::Serializer,
|
||||
{
|
||||
self.delegate
|
||||
.serialize(CaptureKey::new(self.out, serializer))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, S> ser::Serializer for CaptureKey<'a, S>
|
||||
where
|
||||
S: ser::Serializer,
|
||||
{
|
||||
type Ok = S::Ok;
|
||||
type Error = S::Error;
|
||||
type SerializeSeq = S::SerializeSeq;
|
||||
type SerializeTuple = S::SerializeTuple;
|
||||
type SerializeTupleStruct = S::SerializeTupleStruct;
|
||||
type SerializeTupleVariant = S::SerializeTupleVariant;
|
||||
type SerializeMap = S::SerializeMap;
|
||||
type SerializeStruct = S::SerializeStruct;
|
||||
type SerializeStructVariant = S::SerializeStructVariant;
|
||||
|
||||
fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_bool(v)
|
||||
}
|
||||
|
||||
fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_i8(v)
|
||||
}
|
||||
|
||||
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_i16(v)
|
||||
}
|
||||
|
||||
fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_i32(v)
|
||||
}
|
||||
|
||||
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_i64(v)
|
||||
}
|
||||
|
||||
serde_if_integer128! {
|
||||
fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_i128(v)
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_u8(v)
|
||||
}
|
||||
|
||||
fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_u16(v)
|
||||
}
|
||||
|
||||
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_u32(v)
|
||||
}
|
||||
|
||||
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_u64(v)
|
||||
}
|
||||
|
||||
serde_if_integer128! {
|
||||
fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_string()));
|
||||
self.delegate.serialize_u128(v)
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> {
|
||||
self.delegate.serialize_f32(v)
|
||||
}
|
||||
|
||||
fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> {
|
||||
self.delegate.serialize_f64(v)
|
||||
}
|
||||
|
||||
fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error> {
|
||||
self.delegate.serialize_char(v)
|
||||
}
|
||||
|
||||
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(v.to_owned()));
|
||||
self.delegate.serialize_str(v)
|
||||
}
|
||||
|
||||
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error> {
|
||||
self.delegate.serialize_bytes(v)
|
||||
}
|
||||
|
||||
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
|
||||
self.delegate.serialize_none()
|
||||
}
|
||||
|
||||
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
self.delegate
|
||||
.serialize_some(&CaptureKey::new(self.out, value))
|
||||
}
|
||||
|
||||
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
||||
self.delegate.serialize_unit()
|
||||
}
|
||||
|
||||
fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, Self::Error> {
|
||||
self.delegate.serialize_unit_struct(name)
|
||||
}
|
||||
|
||||
fn serialize_unit_variant(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
variant: &'static str,
|
||||
) -> Result<Self::Ok, Self::Error> {
|
||||
self.out.set(Some(variant.to_owned()));
|
||||
self.delegate
|
||||
.serialize_unit_variant(name, variant_index, variant)
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct<T>(
|
||||
self,
|
||||
name: &'static str,
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
self.delegate
|
||||
.serialize_newtype_struct(name, &CaptureKey::new(self.out, value))
|
||||
}
|
||||
|
||||
fn serialize_newtype_variant<T>(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
variant: &'static str,
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
self.delegate
|
||||
.serialize_newtype_variant(name, variant_index, variant, value)
|
||||
}
|
||||
|
||||
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
|
||||
self.delegate.serialize_seq(len)
|
||||
}
|
||||
|
||||
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> {
|
||||
self.delegate.serialize_tuple(len)
|
||||
}
|
||||
|
||||
fn serialize_tuple_struct(
|
||||
self,
|
||||
name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeTupleStruct, Self::Error> {
|
||||
self.delegate.serialize_tuple_struct(name, len)
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
variant: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
||||
self.delegate
|
||||
.serialize_tuple_variant(name, variant_index, variant, len)
|
||||
}
|
||||
|
||||
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
||||
self.delegate.serialize_map(len)
|
||||
}
|
||||
|
||||
fn serialize_struct(
|
||||
self,
|
||||
name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeStruct, Self::Error> {
|
||||
self.delegate.serialize_struct(name, len)
|
||||
}
|
||||
|
||||
fn serialize_struct_variant(
|
||||
self,
|
||||
name: &'static str,
|
||||
variant_index: u32,
|
||||
variant: &'static str,
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeStructVariant, Self::Error> {
|
||||
self.delegate
|
||||
.serialize_struct_variant(name, variant_index, variant, len)
|
||||
}
|
||||
|
||||
fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
I: IntoIterator,
|
||||
I::Item: Serialize,
|
||||
{
|
||||
self.delegate.collect_seq(iter)
|
||||
}
|
||||
|
||||
fn collect_map<K, V, I>(self, iter: I) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
K: Serialize,
|
||||
V: Serialize,
|
||||
I: IntoIterator<Item = (K, V)>,
|
||||
{
|
||||
self.delegate.collect_map(iter)
|
||||
}
|
||||
|
||||
fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: ?Sized + Display,
|
||||
{
|
||||
self.out.set(Some(value.to_string()));
|
||||
self.delegate.collect_str(value)
|
||||
}
|
||||
|
||||
fn is_human_readable(&self) -> bool {
|
||||
self.delegate.is_human_readable()
|
||||
}
|
||||
}
|
||||
35
zeroidc/vendor/serde_path_to_error/src/wrap.rs
vendored
Normal file
35
zeroidc/vendor/serde_path_to_error/src/wrap.rs
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
use crate::{Chain, Track};
|
||||
|
||||
// Wrapper that attaches context to a `Visitor`, `SeqAccess` or `EnumAccess`.
|
||||
pub struct Wrap<'a, 'b, X> {
|
||||
pub(crate) delegate: X,
|
||||
pub(crate) chain: &'a Chain<'a>,
|
||||
pub(crate) track: &'b Track,
|
||||
}
|
||||
|
||||
// Wrapper that attaches context to a `VariantAccess`.
|
||||
pub struct WrapVariant<'a, 'b, X> {
|
||||
pub(crate) delegate: X,
|
||||
pub(crate) chain: Chain<'a>,
|
||||
pub(crate) track: &'b Track,
|
||||
}
|
||||
|
||||
impl<'a, 'b, X> Wrap<'a, 'b, X> {
|
||||
pub(crate) fn new(delegate: X, chain: &'a Chain<'a>, track: &'b Track) -> Self {
|
||||
Wrap {
|
||||
delegate,
|
||||
chain,
|
||||
track,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, X> WrapVariant<'a, 'b, X> {
|
||||
pub(crate) fn new(delegate: X, chain: Chain<'a>, track: &'b Track) -> Self {
|
||||
WrapVariant {
|
||||
delegate,
|
||||
chain,
|
||||
track,
|
||||
}
|
||||
}
|
||||
}
|
||||
215
zeroidc/vendor/serde_path_to_error/tests/deserialize.rs
vendored
Normal file
215
zeroidc/vendor/serde_path_to_error/tests/deserialize.rs
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
#![allow(clippy::unreadable_literal, dead_code)]
|
||||
|
||||
use serde::{serde_if_integer128, Deserialize};
|
||||
use serde_derive::Deserialize;
|
||||
use std::collections::BTreeMap as Map;
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn test<'de, T>(json: &'de str, expected: &str)
|
||||
where
|
||||
T: Deserialize<'de> + Debug,
|
||||
{
|
||||
let de = &mut serde_json::Deserializer::from_str(json);
|
||||
let result: Result<T, _> = serde_path_to_error::deserialize(de);
|
||||
let path = result.unwrap_err().path().to_string();
|
||||
assert_eq!(path, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_struct() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Package {
|
||||
name: String,
|
||||
dependencies: Map<String, Dependency>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Dependency {
|
||||
version: String,
|
||||
}
|
||||
|
||||
let j = r#"{
|
||||
"name": "demo",
|
||||
"dependencies": {
|
||||
"serde": {
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
|
||||
test::<Package>(j, "dependencies.serde.version");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Package {
|
||||
dependencies: Vec<Dependency>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Dependency {
|
||||
name: String,
|
||||
version: String,
|
||||
}
|
||||
|
||||
let j = r#"{
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "serde",
|
||||
"version": "1.0"
|
||||
},
|
||||
{
|
||||
"name": "serde_json",
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
|
||||
test::<Package>(j, "dependencies[1].version");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_option() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Package {
|
||||
dependency: Option<Dependency>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Dependency {
|
||||
version: String,
|
||||
}
|
||||
|
||||
let j = r#"{
|
||||
"dependency": {
|
||||
"version": 1
|
||||
}
|
||||
}"#;
|
||||
|
||||
test::<Package>(j, "dependency.version");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_struct_variant() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Package {
|
||||
dependency: Dependency,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum Dependency {
|
||||
Struct { version: String },
|
||||
}
|
||||
|
||||
let j = r#"{
|
||||
"dependency": {
|
||||
"Struct": {
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
|
||||
test::<Package>(j, "dependency.Struct.version");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple_variant() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Package {
|
||||
dependency: Dependency,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
enum Dependency {
|
||||
Tuple(String, String),
|
||||
}
|
||||
|
||||
let j = r#"{
|
||||
"dependency": {
|
||||
"Tuple": ["serde", 1]
|
||||
}
|
||||
}"#;
|
||||
|
||||
test::<Package>(j, "dependency.Tuple[1]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unknown_field() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Package {
|
||||
dependency: Dependency,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Dependency {
|
||||
version: String,
|
||||
}
|
||||
|
||||
let j = r#"{
|
||||
"dependency": {
|
||||
"version": "1.0",
|
||||
"name": "serde"
|
||||
}
|
||||
}"#;
|
||||
|
||||
test::<Package>(j, "dependency.name");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_length() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Package {
|
||||
dependency: Dependency,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Dependency(String, String);
|
||||
|
||||
let j = r#"{
|
||||
"dependency": ["serde"]
|
||||
}"#;
|
||||
|
||||
test::<Package>(j, "dependency");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_syntax_error() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Package {
|
||||
dependency: Dependency,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Dependency {
|
||||
version: String,
|
||||
}
|
||||
|
||||
let j = r#"{
|
||||
"dependency": {
|
||||
"error": *
|
||||
}"#;
|
||||
|
||||
test::<Package>(j, "dependency.error");
|
||||
}
|
||||
|
||||
serde_if_integer128! {
|
||||
#[test]
|
||||
fn test_u128() {
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Container {
|
||||
n: u128,
|
||||
}
|
||||
|
||||
let j = r#"{
|
||||
"n": 130033514578017493995102500318550798591
|
||||
}"#;
|
||||
|
||||
let de = &mut serde_json::Deserializer::from_str(j);
|
||||
let container: Container =
|
||||
serde_path_to_error::deserialize(de).expect("failed to deserialize");
|
||||
|
||||
assert_eq!(container.n, 130033514578017493995102500318550798591u128);
|
||||
}
|
||||
}
|
||||
48
zeroidc/vendor/serde_path_to_error/tests/serialize.rs
vendored
Normal file
48
zeroidc/vendor/serde_path_to_error/tests/serialize.rs
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
use serde::Serialize;
|
||||
use serde_derive::Serialize;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn test<T>(value: &T, expected: &str)
|
||||
where
|
||||
T: ?Sized + Serialize + Debug,
|
||||
{
|
||||
let mut out = Vec::new();
|
||||
let ser = &mut serde_json::Serializer::new(&mut out);
|
||||
let result = serde_path_to_error::serialize(value, ser);
|
||||
let path = result.unwrap_err().path().to_string();
|
||||
assert_eq!(path, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_refcell_already_borrowed() {
|
||||
#[derive(Serialize, Debug)]
|
||||
struct Outer<'a> {
|
||||
k: Inner<'a>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
struct Inner<'a> {
|
||||
refcell: &'a RefCell<String>,
|
||||
}
|
||||
|
||||
let refcell = RefCell::new(String::new());
|
||||
let outer = Outer {
|
||||
k: Inner { refcell: &refcell },
|
||||
};
|
||||
|
||||
let _borrowed = refcell.borrow_mut();
|
||||
test(&outer, "k.refcell");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_map_nonstring_key() {
|
||||
let mut inner_map = BTreeMap::new();
|
||||
inner_map.insert(b"", 0);
|
||||
|
||||
let mut outer_map = BTreeMap::new();
|
||||
outer_map.insert("k", inner_map);
|
||||
|
||||
test(&outer_map, "k");
|
||||
}
|
||||
Reference in New Issue
Block a user