Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

View File

@@ -0,0 +1 @@
{"files":{"Cargo.lock":"ff63fee3585f2195c0385323d7a4b98d5b117fd145174d30ab0e00a74ef58ad6","Cargo.toml":"5bc832a6946ecc98f75fd10fb4415809f4b7cd51a4c1b96922e8386276ee629e","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"a1cb529cbebaea0cfd4258796e7723e00eb8c6f3f8d5b2c47a49dc4febde7f36","build.rs":"77ff0e288b258aea6e06d8931e3455d95eee0f857ad4e897efdfe414edbcd255","src/any.rs":"2799f6ccf924bfde3866b634914cf5648c211f9cedaa980e20694ddc9a2efdb9","src/de.rs":"6a1de29ce8eca204b652bf7766b0bb7337efc6131df23aac7df16fe0e0f1fb1f","src/error.rs":"abcb24aca58932c09acf59f309879568e5614a18da7895a6efbeaca8dd31c38b","src/features_check/error.rs":"1f2b5d89f9d59ad84a9b77566f9446d36ce430e45eaffdcc30701e8e4de289b9","src/features_check/mod.rs":"55fc384622f1bf009ad4ee424aea2c41ffc63fbef89b688c4e272b0442b22df7","src/lib.rs":"ab82ec814d11f18c8123bc04d31b3747e99a883f6c5e2d956794f3f073f8de0c","src/macros.rs":"49a81da2c9d1d30f90fbb098f80a1087f452f2b040e8acdaea22882be6f7525f","src/map.rs":"56f8817b57c5b144575d2c20d3976adb90e1d56d5128cb3fda88c103144fd5da","src/private.rs":"343e97df25756ca3842c25a786af8ece643f402aea350b8f2c03fd363e2a6767","src/sealed.rs":"4f0585efc022ec7f5204d1d1faadf66807e624086f75e1c08afab7fc3f1fa4de","src/ser.rs":"76a653a8b1afb74707d2ca906de138d70eecb4c1f80322a2bd108ab7aaa38108","tests/compiletest.rs":"4e381aa8ca3eabb7ac14d1e0c3700b3223e47640547a6988cfa13ad68255f60f","tests/readme.rs":"5912a854d3c2d14d9da6b014c7af611b21217c9d5eadec3a874be41945742196","tests/traitobject.rs":"bbaae0d969b5b971e29efa16f7166850944006dc85abf6fa212e31f5e27d4cd0","tests/ui/missing-supertrait.rs":"4660ac0656579f2d7e4186c4a2158ac96a72b15c136cf06840be3812412c187d","tests/ui/missing-supertrait.stderr":"290d5197f88225a57dc79aeafefab781513a9fc85f4c0f94935d500be44865c6"},"package":"259d404d09818dec19332e31d94558aeb442fea04c817006456c24b5460bbd4b"}

282
vendor/erased-serde/Cargo.lock generated vendored Normal file
View File

@@ -0,0 +1,282 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "dissimilar"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8975ffdaa0ef3661bfe02dbdcc06c9f829dfafe6a3c474de366a8d5e44276921"
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "erased-serde"
version = "0.4.8"
dependencies = [
"rustversion",
"serde",
"serde_cbor",
"serde_core",
"serde_derive",
"serde_json",
"trybuild",
"typeid",
]
[[package]]
name = "glob"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
[[package]]
name = "half"
version = "1.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403"
[[package]]
name = "hashbrown"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
[[package]]
name = "indexmap"
version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "206a8042aec68fa4a62e8d3f7aa4ceb508177d9324faf261e1959e495b7a1921"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "memchr"
version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]]
name = "proc-macro2"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustversion"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "ryu"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "serde"
version = "1.0.221"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "341877e04a22458705eb4e131a1508483c877dca2792b3781d4e5d8a6019ec43"
dependencies = [
"serde_core",
]
[[package]]
name = "serde_cbor"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5"
dependencies = [
"half",
"serde",
]
[[package]]
name = "serde_core"
version = "1.0.221"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c459bc0a14c840cb403fc14b148620de1e0778c96ecd6e0c8c3cacb6d8d00fe"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.221"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6185cf75117e20e62b1ff867b9518577271e58abe0037c40bb4794969355ab0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.144"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56177480b00303e689183f110b4e727bb4211d692c62d4fcd16d02be93077d40"
dependencies = [
"itoa",
"memchr",
"ryu",
"serde_core",
]
[[package]]
name = "serde_spanned"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40734c41988f7306bb04f0ecf60ec0f3f1caa34290e4e8ea471dcd3346483b83"
dependencies = [
"serde",
]
[[package]]
name = "syn"
version = "2.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "target-triple"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ac9aa371f599d22256307c24a9d748c041e548cbf599f35d890f9d365361790"
[[package]]
name = "termcolor"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
dependencies = [
"winapi-util",
]
[[package]]
name = "toml"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75129e1dc5000bfbaa9fee9d1b21f974f9fbad9daec557a521ee6e080825f6e8"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_datetime"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bade1c3e902f58d73d3f294cd7f20391c1cb2fbcb643b73566bc773971df91e3"
dependencies = [
"serde",
]
[[package]]
name = "toml_parser"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b551886f449aa90d4fe2bdaa9f4a2577ad2dde302c61ecf262d80b116db95c10"
dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc842091f2def52017664b53082ecbbeb5c7731092bad69d2c63050401dfd64"
[[package]]
name = "trybuild"
version = "1.0.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ded9fdb81f30a5708920310bfcd9ea7482ff9cba5f54601f7a19a877d5c2392"
dependencies = [
"dissimilar",
"glob",
"serde",
"serde_derive",
"serde_json",
"target-triple",
"termcolor",
"toml",
]
[[package]]
name = "typeid"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c"
[[package]]
name = "unicode-ident"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
[[package]]
name = "winapi-util"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys",
]
[[package]]
name = "windows-link"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65"
[[package]]
name = "windows-sys"
version = "0.61.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e201184e40b2ede64bc2ea34968b28e33622acdbbf37104f0e4a33f7abe657aa"
dependencies = [
"windows-link",
]
[[package]]
name = "winnow"
version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf"

102
vendor/erased-serde/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,102 @@
# 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 = "2021"
rust-version = "1.61"
name = "erased-serde"
version = "0.4.8"
authors = ["David Tolnay <dtolnay@gmail.com>"]
build = "build.rs"
exclude = ["benches"]
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Type-erased Serialize and Serializer traits"
documentation = "https://docs.rs/erased-serde"
readme = "README.md"
keywords = [
"serde",
"erasure",
]
categories = [
"encoding",
"rust-patterns",
"no-std",
]
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/erased-serde"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = [
"--generate-link-to-definition",
"--extern-html-root-url=core=https://doc.rust-lang.org",
"--extern-html-root-url=alloc=https://doc.rust-lang.org",
"--extern-html-root-url=std=https://doc.rust-lang.org",
]
[features]
alloc = ["serde_core/alloc"]
default = ["std"]
std = [
"alloc",
"serde_core/std",
]
unstable-debug = []
[lib]
name = "erased_serde"
path = "src/lib.rs"
[[test]]
name = "compiletest"
path = "tests/compiletest.rs"
[[test]]
name = "test"
path = "tests/readme.rs"
[[test]]
name = "traitobject"
path = "tests/traitobject.rs"
[dependencies.serde_core]
version = "1.0.220"
default-features = false
[dependencies.typeid]
version = "1"
[dev-dependencies.rustversion]
version = "1.0.13"
[dev-dependencies.serde]
version = "1.0.220"
[dev-dependencies.serde_cbor]
version = "0.11.2"
[dev-dependencies.serde_derive]
version = "1.0.220"
[dev-dependencies.serde_json]
version = "1.0.99"
[dev-dependencies.trybuild]
version = "1.0.108"
features = ["diff"]
[target."cfg(any())".dependencies.serde]
version = "1.0.220"
default-features = false

176
vendor/erased-serde/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,176 @@
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

23
vendor/erased-serde/LICENSE-MIT vendored Normal file
View 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.

149
vendor/erased-serde/README.md vendored Normal file
View File

@@ -0,0 +1,149 @@
Erased Serde
============
[<img alt="github" src="https://img.shields.io/badge/github-dtolnay/erased--serde-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/erased-serde)
[<img alt="crates.io" src="https://img.shields.io/crates/v/erased-serde.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/erased-serde)
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-erased--serde-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/erased-serde)
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/dtolnay/erased-serde/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/dtolnay/erased-serde/actions?query=branch%3Amaster)
This crate provides type-erased versions of Serde's `Serialize`, `Serializer`
and `Deserializer` traits that can be used as [trait objects].
[trait objects]: https://doc.rust-lang.org/book/first-edition/trait-objects.html
- [`erased_serde::Serialize`](https://docs.rs/erased-serde/0.4/erased_serde/trait.Serialize.html)
- [`erased_serde::Serializer`](https://docs.rs/erased-serde/0.4/erased_serde/trait.Serializer.html)
- [`erased_serde::Deserializer`](https://docs.rs/erased-serde/0.4/erased_serde/trait.Deserializer.html)
The usual Serde `Serialize`, `Serializer` and `Deserializer` traits cannot be
used as trait objects like `&dyn Serialize` or boxed trait objects like
`Box<dyn Serialize>` because of Rust's ["object safety" rules]. In particular,
all three traits contain generic methods which cannot be made into a trait
object.
["object safety" rules]: http://huonw.github.io/blog/2015/01/object-safety/
This library should be considered a low-level building block for interacting
with Serde APIs in an object-safe way. Most use cases will require higher level
functionality such as provided by [`typetag`] which uses this crate internally.
[`typetag`]: https://github.com/dtolnay/typetag
**The traits in this crate work seamlessly with any existing Serde `Serialize`
and `Deserialize` type and any existing Serde `Serializer` and `Deserializer`
format.**
```toml
[dependencies]
serde = "1.0"
erased-serde = "0.4"
```
## Serialization
```rust
use erased_serde::{Serialize, Serializer};
use std::collections::BTreeMap as Map;
use std::io;
fn main() {
// Construct some serializers.
let json = &mut serde_json::Serializer::new(io::stdout());
let cbor = &mut serde_cbor::Serializer::new(serde_cbor::ser::IoWrite::new(io::stdout()));
// The values in this map are boxed trait objects. Ordinarily this would not
// be possible with serde::Serializer because of object safety, but type
// erasure makes it possible with erased_serde::Serializer.
let mut formats: Map<&str, Box<dyn Serializer>> = Map::new();
formats.insert("json", Box::new(<dyn Serializer>::erase(json)));
formats.insert("cbor", Box::new(<dyn Serializer>::erase(cbor)));
// These are boxed trait objects as well. Same thing here - type erasure
// makes this possible.
let mut values: Map<&str, Box<dyn Serialize>> = Map::new();
values.insert("vec", Box::new(vec!["a", "b"]));
values.insert("int", Box::new(65536));
// Pick a Serializer out of the formats map.
let format = formats.get_mut("json").unwrap();
// Pick a Serialize out of the values map.
let value = values.get("vec").unwrap();
// This line prints `["a","b"]` to stdout.
value.erased_serialize(format).unwrap();
}
```
## Deserialization
```rust
use erased_serde::Deserializer;
use std::collections::BTreeMap as Map;
fn main() {
static JSON: &[u8] = br#"{"A": 65, "B": 66}"#;
static CBOR: &[u8] = &[162, 97, 65, 24, 65, 97, 66, 24, 66];
// Construct some deserializers.
let json = &mut serde_json::Deserializer::from_slice(JSON);
let cbor = &mut serde_cbor::Deserializer::from_slice(CBOR);
// The values in this map are boxed trait objects, which is not possible
// with the normal serde::Deserializer because of object safety.
let mut formats: Map<&str, Box<dyn Deserializer>> = Map::new();
formats.insert("json", Box::new(<dyn Deserializer>::erase(json)));
formats.insert("cbor", Box::new(<dyn Deserializer>::erase(cbor)));
// Pick a Deserializer out of the formats map.
let format = formats.get_mut("json").unwrap();
let data: Map<String, usize> = erased_serde::deserialize(format).unwrap();
println!("{}", data["A"] + data["B"]);
}
```
## How it works
This crate is based on a general technique for building trait objects of traits
that have generic methods (like all of Serde's traits). [This example code]
demonstrates the technique applied to a simplified case of a single generic
method. [Try it in the playground.]
[This example code]: https://github.com/dtolnay/erased-serde/blob/master/explanation/main.rs
[Try it in the playground.]: https://play.rust-lang.org/?gist=c1111875e7462ba3d0190aacb2fc2211
In erased-serde things are a bit more complicated than in the example for three
reasons but the idea is the same.
- We need to deal with trait methods that take `self` by value -- effectively by
implementing the object-safe trait for `Option<T>` where `T` implements the
real trait.
- We need to deal with traits that have associated types like `Serializer::Ok`
and `Visitor::Value` -- by carefully short-term stashing things behind a
pointer.
- We need to support trait methods that have a generic type in the return type
but none of the argument types, like `SeqAccess::next_element` -- this can be
flipped around into a callback style where the return value is instead passed
on to a generic argument.
In the future maybe the Rust compiler will be able to apply this technique
automatically to any trait that is not already object safe by the current rules.
<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>

31
vendor/erased-serde/build.rs vendored Normal file
View File

@@ -0,0 +1,31 @@
use std::env;
use std::process::Command;
use std::str;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
};
if minor >= 80 {
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
}
if minor < 78 {
println!("cargo:rustc-cfg=no_diagnostic_namespace");
}
}
fn rustc_minor_version() -> Option<u32> {
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
pieces.next()?.parse().ok()
}

107
vendor/erased-serde/src/any.rs vendored Normal file
View File

@@ -0,0 +1,107 @@
use alloc::boxed::Box;
use core::any::TypeId;
use core::mem::{self, MaybeUninit};
use core::ptr;
#[cfg(feature = "unstable-debug")]
use core::any;
pub struct Any {
value: Value,
drop: unsafe fn(&mut Value),
type_id: TypeId,
/// For panic messages only. Not used for comparison.
#[cfg(feature = "unstable-debug")]
type_name: &'static str,
}
union Value {
ptr: *mut (),
inline: [MaybeUninit<usize>; 2],
}
fn is_small<T>() -> bool {
mem::size_of::<T>() <= mem::size_of::<Value>()
&& mem::align_of::<T>() <= mem::align_of::<Value>()
}
impl Any {
// This is unsafe -- caller must not hold on to the Any beyond the lifetime
// of T.
//
// Example of bad code:
//
// let s = "bad".to_owned();
// let a = Any::new(&s);
// drop(s);
//
// Now `a.as_ref()` and `a.take()` return references to a dead String.
pub(crate) unsafe fn new<T>(t: T) -> Self {
let value: Value;
let drop: unsafe fn(&mut Value);
let type_id = typeid::of::<T>();
if is_small::<T>() {
let mut inline = [MaybeUninit::uninit(); 2];
unsafe { ptr::write(inline.as_mut_ptr().cast::<T>(), t) };
value = Value { inline };
unsafe fn inline_drop<T>(value: &mut Value) {
unsafe { ptr::drop_in_place(value.inline.as_mut_ptr().cast::<T>()) }
}
drop = inline_drop::<T>;
} else {
let ptr = Box::into_raw(Box::new(t)).cast::<()>();
value = Value { ptr };
unsafe fn ptr_drop<T>(value: &mut Value) {
mem::drop(unsafe { Box::from_raw(value.ptr.cast::<T>()) });
}
drop = ptr_drop::<T>;
}
Any {
value,
drop,
type_id,
#[cfg(feature = "unstable-debug")]
type_name: any::type_name::<T>(),
}
}
// This is unsafe -- caller is responsible that T is the correct type.
pub(crate) unsafe fn take<T>(mut self) -> T {
if self.type_id != typeid::of::<T>() {
self.invalid_cast_to::<T>();
}
if is_small::<T>() {
let ptr = unsafe { self.value.inline.as_mut_ptr().cast::<T>() };
let value = unsafe { ptr::read(ptr) };
mem::forget(self);
value
} else {
let ptr = unsafe { self.value.ptr.cast::<T>() };
let box_t = unsafe { Box::from_raw(ptr) };
mem::forget(self);
*box_t
}
}
#[cfg(not(feature = "unstable-debug"))]
fn invalid_cast_to<T>(&self) -> ! {
panic!("invalid cast; enable `unstable-debug` feature to debug");
}
#[cfg(feature = "unstable-debug")]
fn invalid_cast_to<T>(&self) -> ! {
let from = self.type_name;
let to = any::type_name::<T>();
panic!("invalid cast: {} to {}", from, to);
}
}
impl Drop for Any {
fn drop(&mut self) {
unsafe { (self.drop)(&mut self.value) }
}
}

1660
vendor/erased-serde/src/de.rs vendored Normal file

File diff suppressed because it is too large Load Diff

226
vendor/erased-serde/src/error.rs vendored Normal file
View File

@@ -0,0 +1,226 @@
use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::fmt::{self, Debug, Display};
use serde::de::Expected;
/// Error when a `Serializer` or `Deserializer` trait object fails.
pub struct Error {
imp: Box<ErrorImpl>,
}
/// Result type alias where the error is `erased_serde::Error`.
pub type Result<T> = core::result::Result<T, Error>;
pub(crate) fn erase_de<E: serde::de::Error>(e: E) -> Error {
serde::de::Error::custom(e)
}
pub(crate) fn unerase_de<E: serde::de::Error>(e: Error) -> E {
e.as_serde_de_error()
}
impl Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let error = self.as_serde_de_error::<serde::de::value::Error>();
Display::fmt(&error, formatter)
}
}
impl Debug for Error {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let error = self.as_serde_de_error::<serde::de::value::Error>();
Debug::fmt(&error, formatter)
}
}
impl serde::ser::StdError for Error {}
enum ErrorImpl {
Custom(String),
InvalidType {
unexpected: Unexpected,
expected: String,
},
InvalidValue {
unexpected: Unexpected,
expected: String,
},
InvalidLength {
len: usize,
expected: String,
},
UnknownVariant {
variant: String,
expected: &'static [&'static str],
},
UnknownField {
field: String,
expected: &'static [&'static str],
},
MissingField {
field: &'static str,
},
DuplicateField {
field: &'static str,
},
}
enum Unexpected {
Bool(bool),
Unsigned(u64),
Signed(i64),
Float(f64),
Char(char),
Str(String),
Bytes(Vec<u8>),
Unit,
Option,
NewtypeStruct,
Seq,
Map,
Enum,
UnitVariant,
NewtypeVariant,
TupleVariant,
StructVariant,
Other(String),
}
impl serde::ser::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
let imp = Box::new(ErrorImpl::Custom(msg.to_string()));
Error { imp }
}
}
impl serde::de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
let imp = Box::new(ErrorImpl::Custom(msg.to_string()));
Error { imp }
}
fn invalid_type(unexpected: serde::de::Unexpected, expected: &dyn Expected) -> Self {
let imp = Box::new(ErrorImpl::InvalidType {
unexpected: Unexpected::from_serde(unexpected),
expected: expected.to_string(),
});
Error { imp }
}
fn invalid_value(unexpected: serde::de::Unexpected, expected: &dyn Expected) -> Self {
let imp = Box::new(ErrorImpl::InvalidValue {
unexpected: Unexpected::from_serde(unexpected),
expected: expected.to_string(),
});
Error { imp }
}
fn invalid_length(len: usize, expected: &dyn Expected) -> Self {
let imp = Box::new(ErrorImpl::InvalidLength {
len,
expected: expected.to_string(),
});
Error { imp }
}
fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self {
let imp = Box::new(ErrorImpl::UnknownVariant {
variant: variant.to_owned(),
expected,
});
Error { imp }
}
fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self {
let imp = Box::new(ErrorImpl::UnknownField {
field: field.to_owned(),
expected,
});
Error { imp }
}
fn missing_field(field: &'static str) -> Self {
let imp = Box::new(ErrorImpl::MissingField { field });
Error { imp }
}
fn duplicate_field(field: &'static str) -> Self {
let imp = Box::new(ErrorImpl::DuplicateField { field });
Error { imp }
}
}
impl Error {
fn as_serde_de_error<E: serde::de::Error>(&self) -> E {
match self.imp.as_ref() {
ErrorImpl::Custom(msg) => E::custom(msg),
ErrorImpl::InvalidType {
unexpected,
expected,
} => E::invalid_type(unexpected.as_serde(), &expected.as_str()),
ErrorImpl::InvalidValue {
unexpected,
expected,
} => E::invalid_value(unexpected.as_serde(), &expected.as_str()),
ErrorImpl::InvalidLength { len, expected } => {
E::invalid_length(*len, &expected.as_str())
}
ErrorImpl::UnknownVariant { variant, expected } => {
E::unknown_variant(variant, expected)
}
ErrorImpl::UnknownField { field, expected } => E::unknown_field(field, expected),
ErrorImpl::MissingField { field } => E::missing_field(field),
ErrorImpl::DuplicateField { field } => E::duplicate_field(field),
}
}
}
impl Unexpected {
fn from_serde(unexpected: serde::de::Unexpected) -> Self {
match unexpected {
serde::de::Unexpected::Bool(value) => Unexpected::Bool(value),
serde::de::Unexpected::Unsigned(value) => Unexpected::Unsigned(value),
serde::de::Unexpected::Signed(value) => Unexpected::Signed(value),
serde::de::Unexpected::Float(value) => Unexpected::Float(value),
serde::de::Unexpected::Char(value) => Unexpected::Char(value),
serde::de::Unexpected::Str(value) => Unexpected::Str(value.to_owned()),
serde::de::Unexpected::Bytes(value) => Unexpected::Bytes(value.to_owned()),
serde::de::Unexpected::Unit => Unexpected::Unit,
serde::de::Unexpected::Option => Unexpected::Option,
serde::de::Unexpected::NewtypeStruct => Unexpected::NewtypeStruct,
serde::de::Unexpected::Seq => Unexpected::Seq,
serde::de::Unexpected::Map => Unexpected::Map,
serde::de::Unexpected::Enum => Unexpected::Enum,
serde::de::Unexpected::UnitVariant => Unexpected::UnitVariant,
serde::de::Unexpected::NewtypeVariant => Unexpected::NewtypeVariant,
serde::de::Unexpected::TupleVariant => Unexpected::TupleVariant,
serde::de::Unexpected::StructVariant => Unexpected::StructVariant,
serde::de::Unexpected::Other(msg) => Unexpected::Other(msg.to_owned()),
}
}
fn as_serde(&self) -> serde::de::Unexpected {
match self {
Unexpected::Bool(value) => serde::de::Unexpected::Bool(*value),
Unexpected::Unsigned(value) => serde::de::Unexpected::Unsigned(*value),
Unexpected::Signed(value) => serde::de::Unexpected::Signed(*value),
Unexpected::Float(value) => serde::de::Unexpected::Float(*value),
Unexpected::Char(value) => serde::de::Unexpected::Char(*value),
Unexpected::Str(value) => serde::de::Unexpected::Str(value),
Unexpected::Bytes(value) => serde::de::Unexpected::Bytes(value),
Unexpected::Unit => serde::de::Unexpected::Unit,
Unexpected::Option => serde::de::Unexpected::Option,
Unexpected::NewtypeStruct => serde::de::Unexpected::NewtypeStruct,
Unexpected::Seq => serde::de::Unexpected::Seq,
Unexpected::Map => serde::de::Unexpected::Map,
Unexpected::Enum => serde::de::Unexpected::Enum,
Unexpected::UnitVariant => serde::de::Unexpected::UnitVariant,
Unexpected::NewtypeVariant => serde::de::Unexpected::NewtypeVariant,
Unexpected::TupleVariant => serde::de::Unexpected::TupleVariant,
Unexpected::StructVariant => serde::de::Unexpected::StructVariant,
Unexpected::Other(msg) => serde::de::Unexpected::Other(msg),
}
}
}

View File

@@ -0,0 +1 @@
"erased-serde requires that either `std` (default) or `alloc` feature is enabled"

View File

@@ -0,0 +1,13 @@
//! Shows a user-friendly compiler error on incompatible selected features.
#[allow(unused_macros)]
macro_rules! hide_from_rustfmt {
($mod:item) => {
$mod
};
}
#[cfg(not(feature = "alloc"))]
hide_from_rustfmt! {
mod error;
}

144
vendor/erased-serde/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,144 @@
//! [![github]](https://github.com/dtolnay/erased-serde)&ensp;[![crates-io]](https://crates.io/crates/erased-serde)&ensp;[![docs-rs]](https://docs.rs/erased-serde)
//!
//! [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&logo=docs.rs
//!
//! <br>
//!
//! This crate provides type-erased versions of Serde's `Serialize`, `Serializer`
//! and `Deserializer` traits that can be used as [trait objects].
//!
//! [trait objects]: https://doc.rust-lang.org/book/trait-objects.html
//!
//! The usual Serde `Serialize`, `Serializer` and `Deserializer` traits cannot
//! be used as trait objects like `&dyn Serialize` or boxed trait objects like
//! `Box<dyn Serialize>` because of Rust's ["object safety" rules]. In
//! particular, all three traits contain generic methods which cannot be made
//! into a trait object.
//!
//! ["object safety" rules]: http://huonw.github.io/blog/2015/01/object-safety/
//!
//! This library should be considered a low-level building block for interacting
//! with Serde APIs in an object-safe way. Most use cases will require higher
//! level functionality such as provided by [`typetag`] which uses this crate
//! internally.
//!
//! [`typetag`]: https://github.com/dtolnay/typetag
//!
//! **The traits in this crate work seamlessly with any existing Serde
//! `Serialize` and `Deserialize` type and any existing Serde `Serializer` and
//! `Deserializer` format.**
//!
//! ## Serialization
//!
//! ```rust
//! use erased_serde::{Serialize, Serializer};
//! use std::collections::BTreeMap as Map;
//! use std::io;
//!
//! fn main() {
//! // Construct some serializers.
//! let json = &mut serde_json::Serializer::new(io::stdout());
//! let cbor = &mut serde_cbor::Serializer::new(serde_cbor::ser::IoWrite::new(io::stdout()));
//!
//! // The values in this map are boxed trait objects. Ordinarily this would not
//! // be possible with serde::Serializer because of object safety, but type
//! // erasure makes it possible with erased_serde::Serializer.
//! let mut formats: Map<&str, Box<dyn Serializer>> = Map::new();
//! formats.insert("json", Box::new(<dyn Serializer>::erase(json)));
//! formats.insert("cbor", Box::new(<dyn Serializer>::erase(cbor)));
//!
//! // These are boxed trait objects as well. Same thing here - type erasure
//! // makes this possible.
//! let mut values: Map<&str, Box<dyn Serialize>> = Map::new();
//! values.insert("vec", Box::new(vec!["a", "b"]));
//! values.insert("int", Box::new(65536));
//!
//! // Pick a Serializer out of the formats map.
//! let format = formats.get_mut("json").unwrap();
//!
//! // Pick a Serialize out of the values map.
//! let value = values.get("vec").unwrap();
//!
//! // This line prints `["a","b"]` to stdout.
//! value.erased_serialize(format).unwrap();
//! }
//! ```
//!
//! ## Deserialization
//!
//! ```rust
//! use erased_serde::Deserializer;
//! use std::collections::BTreeMap as Map;
//!
//! fn main() {
//! static JSON: &'static [u8] = br#"{"A": 65, "B": 66}"#;
//! static CBOR: &'static [u8] = &[162, 97, 65, 24, 65, 97, 66, 24, 66];
//!
//! // Construct some deserializers.
//! let json = &mut serde_json::Deserializer::from_slice(JSON);
//! let cbor = &mut serde_cbor::Deserializer::from_slice(CBOR);
//!
//! // The values in this map are boxed trait objects, which is not possible
//! // with the normal serde::Deserializer because of object safety.
//! let mut formats: Map<&str, Box<dyn Deserializer>> = Map::new();
//! formats.insert("json", Box::new(<dyn Deserializer>::erase(json)));
//! formats.insert("cbor", Box::new(<dyn Deserializer>::erase(cbor)));
//!
//! // Pick a Deserializer out of the formats map.
//! let format = formats.get_mut("json").unwrap();
//!
//! let data: Map<String, usize> = erased_serde::deserialize(format).unwrap();
//!
//! println!("{}", data["A"] + data["B"]);
//! }
//! ```
#![doc(html_root_url = "https://docs.rs/erased-serde/0.4.8")]
#![no_std]
#![deny(unsafe_op_in_unsafe_fn)]
#![allow(
clippy::box_collection,
clippy::derive_partial_eq_without_eq,
clippy::extra_unused_type_parameters,
clippy::items_after_statements,
clippy::manual_map, // https://github.com/rust-lang/rust-clippy/issues/7820
clippy::missing_errors_doc,
clippy::needless_doctest_main,
clippy::needless_pass_by_ref_mut,
clippy::needless_pass_by_value,
clippy::semicolon_if_nothing_returned, // https://github.com/rust-lang/rust-clippy/issues/7324
clippy::similar_names,
clippy::struct_field_names,
clippy::unused_self,
clippy::wildcard_imports
)]
#![allow(unknown_lints, mismatched_lifetime_syntaxes)]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
extern crate serde_core as serde;
#[macro_use]
mod macros;
mod any;
mod de;
mod error;
mod features_check;
mod map;
mod sealed;
mod ser;
pub use crate::de::{deserialize, Deserializer};
pub use crate::error::{Error, Result};
pub use crate::ser::{serialize, Serialize, Serializer};
// Not public API.
#[doc(hidden)]
#[path = "private.rs"]
pub mod __private;

165
vendor/erased-serde/src/macros.rs vendored Normal file
View File

@@ -0,0 +1,165 @@
/// Implement `serde::Serialize` for a trait object that has
/// `erased_serde::Serialize` as a supertrait.
///
/// ```
/// use erased_serde::serialize_trait_object;
///
/// trait Event: erased_serde::Serialize {
/// /* ... */
/// }
///
/// erased_serde::serialize_trait_object!(Event);
/// ```
///
/// The macro supports traits that have type parameters and/or `where` clauses.
///
/// ```
/// # use erased_serde::serialize_trait_object;
/// #
/// trait Difficult<T>: erased_serde::Serialize where T: Copy {
/// /* ... */
/// }
///
/// serialize_trait_object!(<T> Difficult<T> where T: Copy);
/// ```
#[macro_export]
macro_rules! serialize_trait_object {
($($path:tt)+) => {
$crate::__internal_serialize_trait_object!(begin $($path)+);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __internal_serialize_trait_object {
// Invocation started with `<`, parse generics.
(begin < $($rest:tt)*) => {
$crate::__internal_serialize_trait_object!(generics () () $($rest)*);
};
// Invocation did not start with `<`.
(begin $first:tt $($rest:tt)*) => {
$crate::__internal_serialize_trait_object!(path () ($first) $($rest)*);
};
// End of generics with trailing comma.
(generics ($($generics:tt)*) () , > $($rest:tt)*) => {
$crate::__internal_serialize_trait_object!(path ($($generics)* ,) () $($rest)*);
};
// End of generics without trailing comma.
(generics ($($generics:tt)*) () > $($rest:tt)*) => {
$crate::__internal_serialize_trait_object!(path ($($generics)* ,) () $($rest)*);
};
// Generics open bracket.
(generics ($($generics:tt)*) ($($brackets:tt)*) < $($rest:tt)*) => {
$crate::__internal_serialize_trait_object!(generics ($($generics)* <) ($($brackets)* <) $($rest)*);
};
// Generics close bracket.
(generics ($($generics:tt)*) (< $($brackets:tt)*) > $($rest:tt)*) => {
$crate::__internal_serialize_trait_object!(generics ($($generics)* >) ($($brackets)*) $($rest)*);
};
// Token inside of generics.
(generics ($($generics:tt)*) ($($brackets:tt)*) $first:tt $($rest:tt)*) => {
$crate::__internal_serialize_trait_object!(generics ($($generics)* $first) ($($brackets)*) $($rest)*);
};
// End with `where` clause.
(path ($($generics:tt)*) ($($path:tt)*) where $($rest:tt)*) => {
$crate::__internal_serialize_trait_object!(sendsync ($($generics)*) ($($path)*) ($($rest)*));
};
// End without `where` clause.
(path ($($generics:tt)*) ($($path:tt)*)) => {
$crate::__internal_serialize_trait_object!(sendsync ($($generics)*) ($($path)*) ());
};
// Token inside of path.
(path ($($generics:tt)*) ($($path:tt)*) $first:tt $($rest:tt)*) => {
$crate::__internal_serialize_trait_object!(path ($($generics)*) ($($path)* $first) $($rest)*);
};
// Expand into four impls.
(sendsync ($($generics:tt)*) ($($path:tt)*) ($($bound:tt)*)) => {
$crate::__internal_serialize_trait_object!(impl ($($generics)*) ($($path)*) ($($bound)*) {
fn __check_erased_serialize_supertrait<$($generics)* __T>()
where
__T: ?$crate::__private::Sized + $($path)*,
$($bound)*
{
$crate::__private::require_erased_serialize_impl::<__T>();
}
});
$crate::__internal_serialize_trait_object!(impl ($($generics)*) ($($path)* + $crate::__private::Send) ($($bound)*));
$crate::__internal_serialize_trait_object!(impl ($($generics)*) ($($path)* + $crate::__private::Sync) ($($bound)*));
$crate::__internal_serialize_trait_object!(impl ($($generics)*) ($($path)* + $crate::__private::Send + $crate::__private::Sync) ($($bound)*));
};
// The impl.
(impl ($($generics:tt)*) ($($path:tt)*) ($($bound:tt)*) $({$($body:tt)*})*) => {
impl<'erased, $($generics)*> $crate::__private::serde::Serialize for dyn $($path)* + 'erased
where
$($bound)*
{
fn serialize<S>(&self, serializer: S) -> $crate::__private::Result<S::Ok, S::Error>
where
S: $crate::__private::serde::Serializer,
{
$($($body)*)*
$crate::serialize(self, serializer)
}
}
};
}
// TEST ////////////////////////////////////////////////////////////////////////
#[cfg(test)]
mod tests {
use crate::Serialize;
fn assert_serialize<T: ?Sized + serde::Serialize>() {}
#[test]
fn test_plain() {
trait Trait: Serialize {}
serialize_trait_object!(Trait);
assert_serialize::<dyn Trait>();
assert_serialize::<dyn Trait + Send>();
}
#[test]
fn test_type_parameter() {
trait Trait<T>: Serialize {}
serialize_trait_object!(<T> Trait<T>);
assert_serialize::<dyn Trait<u32>>();
assert_serialize::<dyn Trait<u32> + Send>();
}
#[test]
fn test_generic_bound() {
trait Trait<T: PartialEq<T>, U>: Serialize {}
serialize_trait_object!(<T: PartialEq<T>, U> Trait<T, U>);
assert_serialize::<dyn Trait<u32, ()>>();
assert_serialize::<dyn Trait<u32, ()> + Send>();
}
#[test]
fn test_where_clause() {
trait Trait<T>: Serialize
where
T: Clone,
{
}
serialize_trait_object!(<T> Trait<T> where T: Clone);
assert_serialize::<dyn Trait<u32>>();
assert_serialize::<dyn Trait<u32> + Send>();
}
}

25
vendor/erased-serde/src/map.rs vendored Normal file
View File

@@ -0,0 +1,25 @@
pub(crate) trait ResultExt<T, E> {
unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Result<U, E>;
}
impl<T, E> ResultExt<T, E> for Result<T, E> {
unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Result<U, E> {
match self {
Ok(t) => Ok(unsafe { op(t) }),
Err(e) => Err(e),
}
}
}
pub(crate) trait OptionExt<T> {
unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Option<U>;
}
impl<T> OptionExt<T> for Option<T> {
unsafe fn unsafe_map<U>(self, op: unsafe fn(T) -> U) -> Option<U> {
match self {
Some(t) => Some(unsafe { op(t) }),
None => None,
}
}
}

20
vendor/erased-serde/src/private.rs vendored Normal file
View File

@@ -0,0 +1,20 @@
//! Not public API. Used as `$crate::__private` by macros.
#[doc(hidden)]
pub mod serde {
#[doc(hidden)]
pub use serde::*;
}
#[doc(hidden)]
pub use core::marker::{Send, Sized, Sync};
#[doc(hidden)]
pub type Result<T, E> = core::result::Result<T, E>;
#[doc(hidden)]
pub fn require_erased_serialize_impl<T>()
where
T: ?Sized + crate::Serialize,
{
}

11
vendor/erased-serde/src/sealed.rs vendored Normal file
View File

@@ -0,0 +1,11 @@
pub mod serialize {
pub trait Sealed {}
}
pub mod serializer {
pub trait Sealed {}
}
pub mod deserializer {
pub trait Sealed {}
}

1612
vendor/erased-serde/src/ser.rs vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
#[rustversion::attr(not(nightly), ignore = "requires nightly")]
#[cfg_attr(miri, ignore = "incompatible with miri")]
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
}

57
vendor/erased-serde/tests/readme.rs vendored Normal file
View File

@@ -0,0 +1,57 @@
// Please also update README.md when making changes to this code.
use erased_serde::{Deserializer, Serialize, Serializer};
use std::collections::BTreeMap as Map;
use std::io;
#[test]
fn serialization() {
// Construct some serializers.
let json = &mut serde_json::Serializer::new(io::stdout());
let cbor = &mut serde_cbor::Serializer::new(serde_cbor::ser::IoWrite::new(io::stdout()));
// The values in this map are boxed trait objects. Ordinarily this would not
// be possible with serde::Serializer because of object safety, but type
// erasure makes it possible with erased_serde::Serializer.
let mut formats: Map<&str, Box<dyn Serializer>> = Map::new();
formats.insert("json", Box::new(<dyn Serializer>::erase(json)));
formats.insert("cbor", Box::new(<dyn Serializer>::erase(cbor)));
// These are boxed trait objects as well. Same thing here - type erasure
// makes this possible.
let mut values: Map<&str, Box<dyn Serialize>> = Map::new();
values.insert("vec", Box::new(vec!["a", "b"]));
values.insert("int", Box::new(65536));
// Pick a Serializer out of the formats map.
let format = formats.get_mut("json").unwrap();
// Pick a Serialize out of the values map.
let value = values.get("vec").unwrap();
// This line prints `["a","b"]` to stdout.
value.erased_serialize(format).unwrap();
}
#[test]
fn deserialization() {
static JSON: &[u8] = br#"{"A": 65, "B": 66}"#;
static CBOR: &[u8] = &[162, 97, 65, 24, 65, 97, 66, 24, 66];
// Construct some deserializers.
let json = &mut serde_json::Deserializer::from_slice(JSON);
let cbor = &mut serde_cbor::Deserializer::from_slice(CBOR);
// The values in this map are boxed trait objects, which is not possible
// with the normal serde::Deserializer because of object safety.
let mut formats: Map<&str, Box<dyn Deserializer>> = Map::new();
formats.insert("json", Box::new(<dyn Deserializer>::erase(json)));
formats.insert("cbor", Box::new(<dyn Deserializer>::erase(cbor)));
// Pick a Deserializer out of the formats map.
let format = formats.get_mut("json").unwrap();
let data: Map<String, usize> = erased_serde::deserialize(format).unwrap();
println!("{}", data["A"] + data["B"]);
}

View File

@@ -0,0 +1,9 @@
use erased_serde::serialize_trait_object;
pub trait MyTrait: erased_serde::Serialize {}
serialize_trait_object!(MyTrait);
pub trait MyGenericTrait<'a, T>: erased_serde::Serialize {}
serialize_trait_object!(<'a, T> MyGenericTrait<'a, T>);

View File

@@ -0,0 +1,7 @@
use erased_serde::serialize_trait_object;
pub trait MyTrait {}
serialize_trait_object!(MyTrait);
fn main() {}

View File

@@ -0,0 +1,20 @@
error[E0277]: the trait bound `__T: serde::Serialize` is not satisfied
--> tests/ui/missing-supertrait.rs:5:1
|
5 | serialize_trait_object!(MyTrait);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `serde::Serialize` is not implemented for `__T`, so it does not implement `erased_serde::Serialize`
|
= note: required for `__T` to implement `erased_serde::Serialize`
note: required by a bound in `require_erased_serialize_impl`
--> src/private.rs
|
| pub fn require_erased_serialize_impl<T>()
| ----------------------------- required by a bound in this function
| where
| T: ?Sized + crate::Serialize,
| ^^^^^^^^^^^^^^^^ required by this bound in `require_erased_serialize_impl`
= note: this error originates in the macro `$crate::__internal_serialize_trait_object` which comes from the expansion of the macro `serialize_trait_object` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `__T` with trait `Serialize`
|
5 | serialize_trait_object!(MyTrait + serde_core::ser::Serialize);
| ++++++++++++++++++++++++++++