mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 21:48:02 +00:00
Compare commits
421 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 63c65ef742 | |||
| e838b0bd81 | |||
| 041e99c78a | |||
| 07dcc4f7fe | |||
| b88052d875 | |||
| a28292764c | |||
| 2027088741 | |||
| e2d8589976 | |||
| c8a9f99d14 | |||
| 645d04012d | |||
| 100ddada2f | |||
| 2ef1cd4b35 | |||
| be9c3fd69d | |||
| ef522e1d16 | |||
| 1ddb6c2fdb | |||
| eb3f2329af | |||
| 9e8f14816b | |||
| 03da66c805 | |||
| f75426f47e | |||
| 662fc3861c | |||
| 28c10020b9 | |||
| 89c8d85de9 | |||
| 6502838f27 | |||
| c93a0f335a | |||
| 8264e002a7 | |||
| 117ef22142 | |||
| 3fb5e71c33 | |||
| 296db177e2 | |||
| e4a4389177 | |||
| 7aa0453c3b | |||
| 09b78b24e9 | |||
| a622b8a74a | |||
| 399ef081ec | |||
| 3686277e14 | |||
| 807bd20a64 | |||
| ed9a140348 | |||
| 2de7c2bea2 | |||
| e6a4a3772e | |||
| 0fca04e1a6 | |||
| 92bfc8d3af | |||
| fa0312ac45 | |||
| 1920b694aa | |||
| 3bfd41d624 | |||
| 290449f19b | |||
| 3a1f387e69 | |||
| 541603ac94 | |||
| 0666fbfa20 | |||
| ea071ae1d4 | |||
| 992a01bad2 | |||
| d640b5624f | |||
| 48479e4bae | |||
| dfaf48bc09 | |||
| dcbc3e0162 | |||
| 0289d31724 | |||
| 015e39776f | |||
| 6a9a21f178 | |||
| 81ac54b20d | |||
| 6b4e75520a | |||
| b053b4f492 | |||
| 4cf1fec575 | |||
| ee7d77defa | |||
| d0dfc4577e | |||
| bbbd1d24c9 | |||
| fb3a9e0d7c | |||
| 5ffebeb6ef | |||
| 75db73066b | |||
| 2796833c82 | |||
| 95730dc7f7 | |||
| 795261919f | |||
| 3783a30ae7 | |||
| b61ec84886 | |||
| 780a461d92 | |||
| c0ba323166 | |||
| 20a48c9580 | |||
| 09938803af | |||
| 6d0b43a220 | |||
| c604bdbfe4 | |||
| 9fef892f6d | |||
| b1c7db47b8 | |||
| e76e87a430 | |||
| 8a4dfa7231 | |||
| 107018c628 | |||
| a398237930 | |||
| b63c65d7f5 | |||
| f60324e883 | |||
| 361c23a09a | |||
| 43b23c7ea0 | |||
| 6081497506 | |||
| 48e5753e76 | |||
| bbba632ab3 | |||
| e77db40b8d | |||
| 2c1f62d4b4 | |||
| 1aebdc2760 | |||
| 705e58be8c | |||
| 7c2c12aa43 | |||
| a0f850f15b | |||
| fccb9499bc | |||
| a139ab2572 | |||
| 1d910a484c | |||
| ee9166ec97 | |||
| b5a9eff32e | |||
| 9441a29663 | |||
| ab6588ef74 | |||
| 1d11f03449 | |||
| e11d01fe1d | |||
| a901f50850 | |||
| c399e9c368 | |||
| 25381be0c9 | |||
| ef2a7c753f | |||
| 99f165b45a | |||
| 2fb5560746 | |||
| bd653ab30c | |||
| b5d68aedaa | |||
| 624879c4c6 | |||
| bd9e9abf35 | |||
| 3e4a23cbd0 | |||
| 6326ceec3f | |||
| 8f4d37c7ec | |||
| 1b8290b318 | |||
| 48193fbccd | |||
| 51799dd654 | |||
| 732ac49321 | |||
| ac8ea72d88 | |||
| f583401284 | |||
| 2d88228b7d | |||
| 0c6a2bbf79 | |||
| a80d830f27 | |||
| 5f3fd9994e | |||
| d6de911855 | |||
| 04af32230e | |||
| 4cb8d079f8 | |||
| 6ab55a1e52 | |||
| acfd19cb46 | |||
| e3058105f0 | |||
| dc200a6450 | |||
| 2c0999a0b9 | |||
| dd460f82a1 | |||
| c3d637f397 | |||
| 479a00a215 | |||
| c42e7c8012 | |||
| 5b8e0657d4 | |||
| 9fc0d13e2c | |||
| bc22641359 | |||
| 05098105a8 | |||
| 5b23634dc6 | |||
| 32f0d00ff9 | |||
| 9d87851f0c | |||
| c0296ee11b | |||
| 54671259aa | |||
| 994f7c7924 | |||
| 7a8e4977e2 | |||
| fb7b6ea7ea | |||
| 063dd5b93f | |||
| a38aa31ade | |||
| f42b2581da | |||
| 2ba406726f | |||
| 7e9826e17b | |||
| f4dcc5c918 | |||
| 8b1887c440 | |||
| bbfb1d3504 | |||
| e106feb5ec | |||
| 696f6f56db | |||
| b7b636a23f | |||
| 183b91775e | |||
| 0e70f59021 | |||
| 4d9b76db73 | |||
| 9af132f594 | |||
| 6c063569c0 | |||
| 7e9b98401d | |||
| f301e09e02 | |||
| b80e722f81 | |||
| 1714c262c4 | |||
| a42cdafdcd | |||
| eb4c3f16f7 | |||
| ce86f351d6 | |||
| 0b90f6c96a | |||
| 2198463218 | |||
| be57a5e00a | |||
| b1b09eba60 | |||
| eb1e8c140d | |||
| 43da87939d | |||
| 06d99a13a6 | |||
| 49a911d7de | |||
| 27d6628785 | |||
| e4e2956e79 | |||
| ea2f7b81d9 | |||
| f0dfdb5247 | |||
| 6a5da85fcd | |||
| 0750eee4ff | |||
| ef551a517c | |||
| 1c5ea24f76 | |||
| 88d73e5250 | |||
| 1ff2a972c6 | |||
| bb72fe2726 | |||
| e50b14afee | |||
| cbd1cbef07 | |||
| 01da3f79c9 | |||
| f5e0fbcb14 | |||
| 38c130a303 | |||
| c7393614ff | |||
| a13c6382b6 | |||
| a803ec1c1f | |||
| f7636428ed | |||
| f85c4f2fa9 | |||
| a9a9903107 | |||
| bd4a0981ba | |||
| 35e5cf3e15 | |||
| 07fc9f689e | |||
| 14b0e18c57 | |||
| dd27ec8703 | |||
| db3f00c3b3 | |||
| adcb11ca18 | |||
| b7be637e8c | |||
| 30c4aa2cf4 | |||
| a649190a4d | |||
| d81f0ef652 | |||
| 1a3a49ce7c | |||
| 6b948111ca | |||
| 6adfdc56e5 | |||
| 61531ddd9e | |||
| ccf9c6fc07 | |||
| b25d0ea7f9 | |||
| 4f4557fd05 | |||
| bf400d6799 | |||
| 4d2e36d19b | |||
| df6310e5f5 | |||
| 938ab5ddec | |||
| ef5a0de384 | |||
| 5d186c77a6 | |||
| 44bf3633af | |||
| f261184416 | |||
| df40f80fcf | |||
| e7060ba83d | |||
| d98f0eea3d | |||
| 4f157a8b81 | |||
| d493649f52 | |||
| 0e947e6c3b | |||
| 9249dab54c | |||
| 7440e56c53 | |||
| 0d79306285 | |||
| 37faaf295e | |||
| 650358fa00 | |||
| 6159ead404 | |||
| 692ac99c69 | |||
| 86161ce15f | |||
| 5361c790bb | |||
| 126730edc8 | |||
| 3aec2a96a8 | |||
| 227d039b1e | |||
| 0353354d61 | |||
| 34ae0422f4 | |||
| cc128feb4c | |||
| 7766103174 | |||
| 30f7c7110d | |||
| 50354c2d0b | |||
| c4f67e679f | |||
| 0daafe423f | |||
| 37021910c9 | |||
| 7328b34810 | |||
| fabbd2b097 | |||
| 6814f978d7 | |||
| 4ea403c54a | |||
| f4f6b5af3a | |||
| 2062a3c16d | |||
| 9a53bd9125 | |||
| 4873b48b02 | |||
| e19844c659 | |||
| 93bb9e147c | |||
| ab230e6e44 | |||
| 51ea34b217 | |||
| 1050f6b808 | |||
| 15ec95a98d | |||
| 072145e0e9 | |||
| 92957f17f2 | |||
| 667db558b6 | |||
| f41509261e | |||
| 6d009711a2 | |||
| 354b48fd40 | |||
| 3fd8e52f0c | |||
| 142dce0d3d | |||
| 6aed101630 | |||
| e2ccfd9ea7 | |||
| a07d794f74 | |||
| 90d28fc314 | |||
| 55cf0ac51a | |||
| 07696c1674 | |||
| f803b290f3 | |||
| d96e181150 | |||
| 3ffb86fc70 | |||
| 649a72a587 | |||
| b2676348eb | |||
| 8c036ee5a3 | |||
| d99009f3c6 | |||
| be3c37eb8b | |||
| f0346ae054 | |||
| fa6ce42056 | |||
| a9320db6f9 | |||
| d208762c81 | |||
| 5386897d24 | |||
| 68eb59df0c | |||
| a7f4551669 | |||
| f52d134c14 | |||
| 6660676b0d | |||
| 1d42d3571a | |||
| ebd06eebdb | |||
| f1985823a3 | |||
| 60e4092b8e | |||
| 3d0251666e | |||
| 7770da4929 | |||
| a5fd85a9ef | |||
| abb2a8494d | |||
| a31d0be191 | |||
| d786e750d7 | |||
| 10e4839f83 | |||
| 85e72653c8 | |||
| c9cc8a8924 | |||
| a925ce4119 | |||
| c5f6338ce2 | |||
| 5185487d73 | |||
| efaafd4458 | |||
| a0eb83a5d4 | |||
| 7cc6f7fbb0 | |||
| 44b9496c91 | |||
| 7e1486d0da | |||
| 8170ffef2e | |||
| 4b622f6bbf | |||
| 0ee71c70af | |||
| 6c098e497e | |||
| 41ffa6df7e | |||
| 845b900fd5 | |||
| 7891ae7184 | |||
| bac90d19b9 | |||
| 227bf3023a | |||
| f4535f68c1 | |||
| c6c35b5a31 | |||
| 31e51324e2 | |||
| bc3f24e0e9 | |||
| 2e38e2bf2f | |||
| 819f90d9f6 | |||
| 2eed86cd67 | |||
| 3921b57435 | |||
| 68069d734a | |||
| dc84693507 | |||
| 4cf012c5be | |||
| 17c3c0cf86 | |||
| 210e6c354e | |||
| 41823a96df | |||
| 7ca13ff240 | |||
| 52391fd868 | |||
| 9b2d8dfc6b | |||
| 07ba7ea8dd | |||
| 9f29f6bb4a | |||
| f6c104fd1d | |||
| 8a3a6fb101 | |||
| b5c3b5e8e5 | |||
| 996d171461 | |||
| e1c4517335 | |||
| 6e94a27c76 | |||
| b23a768414 | |||
| 7e19ae8c94 | |||
| 404a1d142a | |||
| 02bd79a0ba | |||
| c3ce2c934a | |||
| 0d71ac84b5 | |||
| 82c3eb7ba4 | |||
| 8932c852a5 | |||
| 9f3dd3c7c4 | |||
| dd9b415ff9 | |||
| 3bb4a5a4f6 | |||
| 6164627bea | |||
| 51aaf496d4 | |||
| bc66aeb0d3 | |||
| 7e7044d457 | |||
| 5498dc0550 | |||
| ff04e8be9b | |||
| 69240c17c5 | |||
| 237434f19c | |||
| 1833914346 | |||
| ab848060f2 | |||
| 7e39623f72 | |||
| 157dc44c51 | |||
| 80d01a3a79 | |||
| 343c060fc1 | |||
| 21c1ab6c50 | |||
| 594ab7745d | |||
| 8cf0ba7fe2 | |||
| 34b52c0b83 | |||
| ec7ddc93cd | |||
| 55a7cedd73 | |||
| 7af97c66b8 | |||
| 1f57084365 | |||
| 56bd369422 | |||
| ff259ec66b | |||
| 6c54aafeb9 | |||
| 5d41404e67 | |||
| 1eccb3c350 | |||
| 77ae1c3bf7 | |||
| b85e28166c | |||
| 0508cb50fc | |||
| 84fdc7df69 | |||
| ab1ca04b2e | |||
| fb2fe409c8 | |||
| 549fac7235 | |||
| c375d8b19b | |||
| 6cf507f808 | |||
| c3c1641c06 | |||
| 1fcda0ebdb | |||
| 8f16ac0a94 | |||
| 737f78c315 | |||
| 4a97386cb9 | |||
| 5b32217877 | |||
| 5b140361a3 | |||
| 678351eac7 | |||
| 999c261d11 | |||
| efbe574209 | |||
| 33b2677384 | |||
| 01ded9f405 | |||
| fc827ecec2 | |||
| 5c785eee58 | |||
| 819db93a3d | |||
| a6690ea2fe |
+70
-54
@@ -3,22 +3,31 @@ name: CI
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
schedule: [cron: "40 1 * * *"]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
RUSTFLAGS: -Dwarnings
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test suite
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@nightly
|
||||
- run: cd test_suite && cargo test --features unstable
|
||||
|
||||
windows:
|
||||
name: Test suite (windows)
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@nightly
|
||||
- run: cd test_suite && cargo test --features unstable -- --skip ui --exact
|
||||
|
||||
@@ -29,8 +38,9 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
rust: [stable, beta]
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: ${{matrix.rust}}
|
||||
@@ -46,8 +56,9 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu, windows]
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@nightly
|
||||
- run: cd serde && cargo build
|
||||
- run: cd serde && cargo build --no-default-features
|
||||
@@ -56,23 +67,10 @@ jobs:
|
||||
- run: cd serde && cargo test --features derive,rc,unstable
|
||||
- run: cd test_suite/no_std && cargo build
|
||||
if: matrix.os != 'windows'
|
||||
|
||||
msrv:
|
||||
name: Rust 1.13.0
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: dtolnay/rust-toolchain@1.13.0
|
||||
- name: Get timestamp for cache
|
||||
id: date
|
||||
run: echo ::set-output name=yearmo::$(date +%Y%m)
|
||||
- uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.cargo/registry/index
|
||||
key: cargo-registry-index-${{steps.date.outputs.yearmo}}
|
||||
- run: cd serde && cargo build --features rc
|
||||
- run: cd serde && cargo build --no-default-features
|
||||
- run: cd serde_test && cargo build
|
||||
- run: cd serde_derive && cargo check --tests
|
||||
env:
|
||||
RUSTFLAGS: --cfg exhaustive ${{env.RUSTFLAGS}}
|
||||
if: matrix.os != 'windows'
|
||||
|
||||
build:
|
||||
name: Rust ${{matrix.rust}}
|
||||
@@ -81,13 +79,16 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
rust: [1.19.0, 1.20.0, 1.21.0, 1.25.0, 1.26.0, 1.34.0]
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: ${{matrix.rust}}
|
||||
- run: cd serde && cargo build --features rc
|
||||
- run: cd serde && cargo build --no-default-features
|
||||
- run: cd serde && cargo build
|
||||
- run: cd serde_test && cargo build
|
||||
|
||||
more:
|
||||
name: Rust ${{matrix.rust}}
|
||||
@@ -96,8 +97,9 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
rust: [1.27.0, 1.28.0]
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: ${{matrix.rust}}
|
||||
@@ -107,11 +109,12 @@ jobs:
|
||||
- run: cd serde && cargo build
|
||||
|
||||
derive:
|
||||
name: Rust 1.31.0
|
||||
name: Rust 1.56.0
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: dtolnay/rust-toolchain@1.31.0
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@1.56.0
|
||||
- run: cd serde && cargo check --no-default-features
|
||||
- run: cd serde && cargo check
|
||||
- run: cd serde_derive && cargo check
|
||||
@@ -119,45 +122,58 @@ jobs:
|
||||
alloc:
|
||||
name: Rust 1.36.0
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@1.36.0
|
||||
- run: cd serde && cargo build --no-default-features --features alloc
|
||||
|
||||
emscripten:
|
||||
name: Emscripten
|
||||
minimal:
|
||||
name: Minimal versions
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@nightly
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 9
|
||||
- name: Install cargo-web
|
||||
run: |
|
||||
CARGO_WEB_RELEASE=$(curl -L -s -H Accept:application/json https://github.com/koute/cargo-web/releases/latest)
|
||||
CARGO_WEB_VERSION=$(echo "${CARGO_WEB_RELEASE}" | jq -r .tag_name)
|
||||
CARGO_WEB_URL="https://github.com/koute/cargo-web/releases/download/${CARGO_WEB_VERSION}/cargo-web-x86_64-unknown-linux-gnu.gz"
|
||||
mkdir -p ~/.cargo/bin
|
||||
curl -L "${CARGO_WEB_URL}" | gzip -d > ~/.cargo/bin/cargo-web
|
||||
chmod +x ~/.cargo/bin/cargo-web
|
||||
- run: cd test_suite && cargo web test --target=asmjs-unknown-emscripten --nodejs
|
||||
continue-on-error: true
|
||||
- run: cd test_suite && cargo web test --target=wasm32-unknown-emscripten --nodejs
|
||||
continue-on-error: true
|
||||
- run: cargo generate-lockfile -Z minimal-versions
|
||||
- run: cargo check --locked --workspace
|
||||
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'pull_request'
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@clippy
|
||||
# The need for -Aredundant_field_names here is a Clippy bug.
|
||||
# https://github.com/rust-lang/rust-clippy/issues/5356
|
||||
- run: cd serde && cargo clippy --features rc,unstable -- -D clippy::all -A clippy::redundant_field_names
|
||||
- run: cd serde_derive && cargo clippy -- -D clippy::all
|
||||
- run: cd serde_derive_internals && cargo clippy -- -D clippy::all
|
||||
- run: cd serde_test && cargo clippy -- -D clippy::all -A clippy::redundant_field_names
|
||||
- run: cd test_suite && cargo clippy --tests --features unstable -- -D clippy::all -A clippy::redundant_field_names
|
||||
- run: cd test_suite/no_std && cargo clippy -- -D clippy::all -A clippy::redundant_field_names
|
||||
- run: cd serde && cargo clippy --features rc,unstable -- -Dclippy::all -Dclippy::pedantic
|
||||
- run: cd serde_derive && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
||||
- run: cd serde_derive_internals && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
||||
- run: cd serde_test && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
||||
- run: cd test_suite && cargo clippy --tests --features unstable -- -Dclippy::all -Dclippy::pedantic
|
||||
- run: cd test_suite/no_std && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
||||
|
||||
miri:
|
||||
name: Miri
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/rust-toolchain@miri
|
||||
- run: cargo miri setup
|
||||
- run: cd serde && cargo miri test --features derive,rc,unstable
|
||||
env:
|
||||
MIRIFLAGS: -Zmiri-strict-provenance
|
||||
- run: cd test_suite && cargo miri test --features unstable
|
||||
env:
|
||||
MIRIFLAGS: -Zmiri-strict-provenance
|
||||
|
||||
outdated:
|
||||
name: Outdated
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'pull_request'
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dtolnay/install@cargo-outdated
|
||||
- run: cargo outdated --workspace --exit-code 1
|
||||
|
||||
@@ -174,28 +174,3 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
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.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.13+]][Rust 1.13] [![serde_derive: rustc 1.31+]][Rust 1.31]
|
||||
# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.19+]][Rust 1.19] [![serde_derive: rustc 1.56+]][Rust 1.56]
|
||||
|
||||
[Build Status]: https://img.shields.io/github/workflow/status/serde-rs/serde/CI/master
|
||||
[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master
|
||||
[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster
|
||||
[Latest Version]: https://img.shields.io/crates/v/serde.svg
|
||||
[crates.io]: https://crates.io/crates/serde
|
||||
[serde: rustc 1.13+]: https://img.shields.io/badge/serde-rustc_1.13+-lightgray.svg
|
||||
[serde_derive: rustc 1.31+]: https://img.shields.io/badge/serde_derive-rustc_1.31+-lightgray.svg
|
||||
[Rust 1.13]: https://blog.rust-lang.org/2016/11/10/Rust-1.13.html
|
||||
[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
|
||||
[serde: rustc 1.19+]: https://img.shields.io/badge/serde-rustc_1.19+-lightgray.svg
|
||||
[serde_derive: rustc 1.56+]: https://img.shields.io/badge/serde_derive-rustc_1.56+-lightgray.svg
|
||||
[Rust 1.19]: https://blog.rust-lang.org/2017/07/20/Rust-1.19.html
|
||||
[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
|
||||
|
||||
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
|
||||
|
||||
@@ -19,7 +19,7 @@ You may be looking for:
|
||||
- [Data formats supported by Serde](https://serde.rs/#data-formats)
|
||||
- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/derive.html)
|
||||
- [Examples](https://serde.rs/examples.html)
|
||||
- [API documentation](https://docs.serde.rs/serde/)
|
||||
- [API documentation](https://docs.rs/serde)
|
||||
- [Release notes](https://github.com/serde-rs/serde/releases)
|
||||
|
||||
## Serde in action
|
||||
@@ -48,7 +48,7 @@ serde_json = "1.0"
|
||||
<p></p>
|
||||
|
||||
```rust
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Point {
|
||||
@@ -77,17 +77,20 @@ fn main() {
|
||||
|
||||
Serde is one of the most widely used Rust libraries so any place that Rustaceans
|
||||
congregate will be able to help you out. For chat, consider trying the
|
||||
[#general] or [#beginners] channels of the unofficial community Discord, the
|
||||
[#rust-usage] channel of the official Rust Project Discord, or the
|
||||
[#general][zulip] stream in Zulip. For asynchronous, consider the [\[rust\] tag
|
||||
on StackOverflow][stackoverflow], the [/r/rust] subreddit which has a pinned
|
||||
weekly easy questions post, or the Rust [Discourse forum][discourse]. It's
|
||||
acceptable to file a support issue in this repo but they tend not to get as many
|
||||
eyes as any of the above and may get closed without a response after some time.
|
||||
[#rust-questions] or [#rust-beginners] channels of the unofficial community
|
||||
Discord (invite: <https://discord.gg/rust-lang-community>), the [#rust-usage] or
|
||||
[#beginners] channels of the official Rust Project Discord (invite:
|
||||
<https://discord.gg/rust-lang>), or the [#general][zulip] stream in Zulip. For
|
||||
asynchronous, consider the [\[rust\] tag on StackOverflow][stackoverflow], the
|
||||
[/r/rust] subreddit which has a pinned weekly easy questions post, or the Rust
|
||||
[Discourse forum][discourse]. It's acceptable to file a support issue in this
|
||||
repo but they tend not to get as many eyes as any of the above and may get
|
||||
closed without a response after some time.
|
||||
|
||||
[#general]: https://discord.com/channels/273534239310479360/274215136414400513
|
||||
[#beginners]: https://discord.com/channels/273534239310479360/273541522815713281
|
||||
[#rust-questions]: https://discord.com/channels/273534239310479360/274215136414400513
|
||||
[#rust-beginners]: https://discord.com/channels/273534239310479360/273541522815713281
|
||||
[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848
|
||||
[#beginners]: https://discord.com/channels/442252698964721669/448238009733742612
|
||||
[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general
|
||||
[stackoverflow]: https://stackoverflow.com/questions/tagged/rust
|
||||
[/r/rust]: https://www.reddit.com/r/rust
|
||||
|
||||
+14
-11
@@ -10,13 +10,13 @@ You may be looking for:
|
||||
- [Data formats supported by Serde](https://serde.rs/#data-formats)
|
||||
- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/derive.html)
|
||||
- [Examples](https://serde.rs/examples.html)
|
||||
- [API documentation](https://docs.serde.rs/serde/)
|
||||
- [API documentation](https://docs.rs/serde)
|
||||
- [Release notes](https://github.com/serde-rs/serde/releases)
|
||||
|
||||
## Serde in action
|
||||
|
||||
```rust
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Point {
|
||||
@@ -45,17 +45,20 @@ fn main() {
|
||||
|
||||
Serde is one of the most widely used Rust libraries so any place that Rustaceans
|
||||
congregate will be able to help you out. For chat, consider trying the
|
||||
[#general] or [#beginners] channels of the unofficial community Discord, the
|
||||
[#rust-usage] channel of the official Rust Project Discord, or the
|
||||
[#general][zulip] stream in Zulip. For asynchronous, consider the [\[rust\] tag
|
||||
on StackOverflow][stackoverflow], the [/r/rust] subreddit which has a pinned
|
||||
weekly easy questions post, or the Rust [Discourse forum][discourse]. It's
|
||||
acceptable to file a support issue in this repo but they tend not to get as many
|
||||
eyes as any of the above and may get closed without a response after some time.
|
||||
[#rust-questions] or [#rust-beginners] channels of the unofficial community
|
||||
Discord (invite: <https://discord.gg/rust-lang-community>, the [#rust-usage] or
|
||||
[#beginners] channels of the official Rust Project Discord (invite:
|
||||
<https://discord.gg/rust-lang>), or the [#general][zulip] stream in Zulip. For
|
||||
asynchronous, consider the [\[rust\] tag on StackOverflow][stackoverflow], the
|
||||
[/r/rust] subreddit which has a pinned weekly easy questions post, or the Rust
|
||||
[Discourse forum][discourse]. It's acceptable to file a support issue in this
|
||||
repo but they tend not to get as many eyes as any of the above and may get
|
||||
closed without a response after some time.
|
||||
|
||||
[#general]: https://discord.com/channels/273534239310479360/274215136414400513
|
||||
[#beginners]: https://discord.com/channels/273534239310479360/273541522815713281
|
||||
[#rust-questions]: https://discord.com/channels/273534239310479360/274215136414400513
|
||||
[#rust-beginners]: https://discord.com/channels/273534239310479360/273541522815713281
|
||||
[#rust-usage]: https://discord.com/channels/442252698964721669/443150878111694848
|
||||
[#beginners]: https://discord.com/channels/442252698964721669/448238009733742612
|
||||
[zulip]: https://rust-lang.zulipchat.com/#narrow/stream/122651-general
|
||||
[stackoverflow]: https://stackoverflow.com/questions/tagged/rust
|
||||
[/r/rust]: https://www.reddit.com/r/rust
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/serde_derive/serde_derive-x86_64-unknown-linux-gnu
|
||||
@@ -0,0 +1,14 @@
|
||||
[workspace]
|
||||
members = ["bin", "proc-macro2"]
|
||||
resolver = "2"
|
||||
|
||||
[patch.crates-io]
|
||||
proc-macro2 = { path = "proc-macro2" }
|
||||
|
||||
[profile.precompiled]
|
||||
inherits = "release"
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
panic = "abort"
|
||||
strip = true
|
||||
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "serde_derive"
|
||||
version = "1.0.172"
|
||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[[bin]]
|
||||
name = "serde_derive"
|
||||
path = "main.rs"
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1"
|
||||
quote = { version = "1", default-features = false }
|
||||
syn = { version = "2.0.25", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
||||
@@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
println!("cargo:rustc-cfg=precompiled");
|
||||
println!("cargo:rustc-cfg=feature=\"deserialize_in_place\"");
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
extern crate proc_macro2;
|
||||
|
||||
use proc_macro2::watt;
|
||||
use proc_macro2::watt::buffer::InputBuffer;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
fn main() {
|
||||
let mut buf = Vec::new();
|
||||
io::stdin().read_to_end(&mut buf).unwrap();
|
||||
|
||||
let mut buf = InputBuffer::new(&buf);
|
||||
let derive = match buf.read_u8() {
|
||||
0 => serde_derive::derive_serialize,
|
||||
1 => serde_derive::derive_deserialize,
|
||||
2 => {
|
||||
serde_derive::DESERIALIZE_IN_PLACE.store(true, Ordering::Relaxed);
|
||||
serde_derive::derive_deserialize
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let input = watt::load(&mut buf);
|
||||
let output = derive(input);
|
||||
let bytes = watt::linearize(output);
|
||||
io::stdout().write_all(&bytes).unwrap();
|
||||
}
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../serde_derive/src
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null
|
||||
set -e -x
|
||||
|
||||
# TODO: Sanitize host filesystem paths. https://github.com/rust-lang/cargo/issues/12137
|
||||
|
||||
cargo +nightly build \
|
||||
--manifest-path bin/Cargo.toml \
|
||||
--bin serde_derive \
|
||||
--profile precompiled \
|
||||
-Z unstable-options \
|
||||
-Z build-std=std,panic_abort \
|
||||
-Z build-std-features=panic_immediate_abort \
|
||||
--target x86_64-unknown-linux-musl \
|
||||
--out-dir serde_derive
|
||||
|
||||
rm -f serde_derive/serde_derive-x86_64-unknown-linux-gnu
|
||||
mv serde_derive/serde_derive{,-x86_64-unknown-linux-gnu}
|
||||
|
||||
#upx --best --lzma serde_derive/serde_derive-x86_64-unknown-linux-gnu
|
||||
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = { package = "proc-macro2-fallback", version = "1" }
|
||||
@@ -0,0 +1,815 @@
|
||||
#[doc(hidden)]
|
||||
pub mod watt;
|
||||
|
||||
use crate::extra::DelimSpan;
|
||||
use crate::watt::Identity;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt::{self, Debug, Display};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::RangeBounds;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub use proc_macro2::{Delimiter, Spacing};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Span {
|
||||
lo: u32,
|
||||
hi: u32,
|
||||
}
|
||||
|
||||
impl Span {
|
||||
pub fn call_site() -> Self {
|
||||
Span { lo: 0, hi: 0 }
|
||||
}
|
||||
|
||||
pub fn join(&self, other: Self) -> Option<Self> {
|
||||
Some(Span {
|
||||
lo: self.lo,
|
||||
hi: other.hi,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum TokenTree {
|
||||
Group(Group),
|
||||
Ident(Ident),
|
||||
Punct(Punct),
|
||||
Literal(Literal),
|
||||
}
|
||||
|
||||
impl TokenTree {
|
||||
pub fn span(&self) -> Span {
|
||||
match self {
|
||||
TokenTree::Group(group) => group.span(),
|
||||
TokenTree::Ident(ident) => ident.span(),
|
||||
TokenTree::Punct(punct) => punct.span(),
|
||||
TokenTree::Literal(literal) => literal.span(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_span(&mut self, span: Span) {
|
||||
match self {
|
||||
TokenTree::Group(group) => group.set_span(span),
|
||||
TokenTree::Ident(ident) => ident.set_span(span),
|
||||
TokenTree::Punct(punct) => punct.set_span(span),
|
||||
TokenTree::Literal(literal) => literal.set_span(span),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Group> for TokenTree {
|
||||
fn from(group: Group) -> Self {
|
||||
TokenTree::Group(group)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ident> for TokenTree {
|
||||
fn from(ident: Ident) -> Self {
|
||||
TokenTree::Ident(ident)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Punct> for TokenTree {
|
||||
fn from(punct: Punct) -> Self {
|
||||
TokenTree::Punct(punct)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Literal> for TokenTree {
|
||||
fn from(literal: Literal) -> Self {
|
||||
TokenTree::Literal(literal)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for TokenTree {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
TokenTree::Group(group) => Debug::fmt(group, formatter),
|
||||
TokenTree::Ident(ident) => {
|
||||
let mut debug = formatter.debug_struct("Ident");
|
||||
debug.field("sym", &format_args!("{}", ident));
|
||||
debug.finish()
|
||||
}
|
||||
TokenTree::Punct(punct) => Debug::fmt(punct, formatter),
|
||||
TokenTree::Literal(literal) => Debug::fmt(literal, formatter),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Group {
|
||||
delimiter: Delimiter,
|
||||
stream: Vec<TokenTree>,
|
||||
span: Span,
|
||||
span_open: Span,
|
||||
span_close: Span,
|
||||
identity: u32,
|
||||
}
|
||||
|
||||
impl Group {
|
||||
pub fn new(delimiter: Delimiter, stream: TokenStream) -> Self {
|
||||
Group {
|
||||
delimiter,
|
||||
stream: stream.content,
|
||||
span: Span::call_site(),
|
||||
span_open: Span::call_site(),
|
||||
span_close: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stream(&self) -> TokenStream {
|
||||
TokenStream {
|
||||
content: self.stream.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delimiter(&self) -> Delimiter {
|
||||
self.delimiter
|
||||
}
|
||||
|
||||
pub fn span(&self) -> Span {
|
||||
self.span
|
||||
}
|
||||
|
||||
pub fn span_open(&self) -> Span {
|
||||
self.span_open
|
||||
}
|
||||
|
||||
pub fn span_close(&self) -> Span {
|
||||
self.span_close
|
||||
}
|
||||
|
||||
pub fn delim_span(&self) -> DelimSpan {
|
||||
DelimSpan {
|
||||
join: self.span,
|
||||
open: self.span_open,
|
||||
close: self.span_close,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_span(&mut self, span: Span) {
|
||||
self.span = span;
|
||||
self.identity |= Identity::RESPANNED;
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Group {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
let (open, close) = match self.delimiter {
|
||||
Delimiter::Parenthesis => ("(", ")"),
|
||||
Delimiter::Brace => ("{ ", "}"),
|
||||
Delimiter::Bracket => ("[", "]"),
|
||||
Delimiter::None => ("", ""),
|
||||
};
|
||||
|
||||
formatter.write_str(open)?;
|
||||
display_tokens(&self.stream, formatter)?;
|
||||
if self.delimiter == Delimiter::Brace && !self.stream.is_empty() {
|
||||
formatter.write_str(" ")?;
|
||||
}
|
||||
formatter.write_str(close)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Group {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut debug = formatter.debug_struct("Group");
|
||||
debug.field("delimiter", &self.delimiter);
|
||||
debug.field("stream", &self.stream);
|
||||
debug.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Ident {
|
||||
fallback: proc_macro2::Ident,
|
||||
span: Span,
|
||||
identity: u32,
|
||||
}
|
||||
|
||||
impl Ident {
|
||||
pub fn new(string: &str, span: Span) -> Self {
|
||||
Ident {
|
||||
fallback: proc_macro2::Ident::new(string, proc_macro2::Span::call_site()),
|
||||
span,
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_raw(string: &str, span: Span) -> Self {
|
||||
Ident {
|
||||
fallback: proc_macro2::Ident::new_raw(string, proc_macro2::Span::call_site()),
|
||||
span,
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn span(&self) -> Span {
|
||||
self.span
|
||||
}
|
||||
|
||||
pub fn set_span(&mut self, span: Span) {
|
||||
self.span = span;
|
||||
self.identity |= Identity::RESPANNED;
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Ident {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
Display::fmt(&self.fallback, formatter)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Ident {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
Debug::fmt(&self.fallback, formatter)
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Ident {}
|
||||
|
||||
impl PartialEq for Ident {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
PartialEq::eq(&self.fallback, &other.fallback)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq<T> for Ident
|
||||
where
|
||||
T: ?Sized + AsRef<str>,
|
||||
{
|
||||
fn eq(&self, other: &T) -> bool {
|
||||
PartialEq::eq(&self.fallback, other)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for Ident {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
Ord::cmp(&self.fallback, &other.fallback)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Ident {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
PartialOrd::partial_cmp(&self.fallback, &other.fallback)
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Ident {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
Hash::hash(&self.fallback, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Punct {
|
||||
fallback: proc_macro2::Punct,
|
||||
span: Span,
|
||||
identity: u32,
|
||||
}
|
||||
|
||||
impl Punct {
|
||||
pub fn new(ch: char, spacing: Spacing) -> Self {
|
||||
Punct {
|
||||
fallback: proc_macro2::Punct::new(ch, spacing),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_char(&self) -> char {
|
||||
self.fallback.as_char()
|
||||
}
|
||||
|
||||
pub fn spacing(&self) -> Spacing {
|
||||
self.fallback.spacing()
|
||||
}
|
||||
|
||||
pub fn span(&self) -> Span {
|
||||
self.span
|
||||
}
|
||||
|
||||
pub fn set_span(&mut self, span: Span) {
|
||||
self.span = span;
|
||||
self.identity |= Identity::RESPANNED;
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Punct {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
Display::fmt(&self.fallback, formatter)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Punct {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
Debug::fmt(&self.fallback, formatter)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Literal {
|
||||
fallback: proc_macro2::Literal,
|
||||
span: Span,
|
||||
identity: u32,
|
||||
}
|
||||
|
||||
impl Literal {
|
||||
pub fn u8_suffixed(n: u8) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u8_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u16_suffixed(n: u16) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u16_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u32_suffixed(n: u32) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u32_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u64_suffixed(n: u64) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u64_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u128_suffixed(n: u128) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u128_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn usize_suffixed(n: usize) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::usize_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i8_suffixed(n: i8) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i8_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i16_suffixed(n: i16) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i16_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i32_suffixed(n: i32) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i32_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i64_suffixed(n: i64) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i64_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i128_suffixed(n: i128) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i128_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn isize_suffixed(n: isize) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::isize_suffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u8_unsuffixed(n: u8) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u8_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u16_unsuffixed(n: u16) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u16_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u32_unsuffixed(n: u32) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u32_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u64_unsuffixed(n: u64) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u64_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u128_unsuffixed(n: u128) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::u128_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn usize_unsuffixed(n: usize) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::usize_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i8_unsuffixed(n: i8) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i8_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i16_unsuffixed(n: i16) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i16_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i32_unsuffixed(n: i32) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i32_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i64_unsuffixed(n: i64) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i64_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn i128_unsuffixed(n: i128) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::i128_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn isize_unsuffixed(n: isize) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::isize_unsuffixed(n),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn f64_unsuffixed(f: f64) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::f64_unsuffixed(f),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn f64_suffixed(f: f64) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::f64_suffixed(f),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn f32_unsuffixed(f: f32) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::f32_unsuffixed(f),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn f32_suffixed(f: f32) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::f32_suffixed(f),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn string(string: &str) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::string(string),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn character(ch: char) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::character(ch),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn byte_string(s: &[u8]) -> Self {
|
||||
Literal {
|
||||
fallback: proc_macro2::Literal::byte_string(s),
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn span(&self) -> Span {
|
||||
self.span
|
||||
}
|
||||
|
||||
pub fn set_span(&mut self, span: Span) {
|
||||
self.span = span;
|
||||
self.identity |= Identity::RESPANNED;
|
||||
}
|
||||
|
||||
pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span> {
|
||||
let _ = range;
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Literal {
|
||||
type Err = LexError;
|
||||
|
||||
fn from_str(repr: &str) -> Result<Self, Self::Err> {
|
||||
let fallback = match proc_macro2::Literal::from_str(repr) {
|
||||
Ok(literal) => literal,
|
||||
Err(error) => {
|
||||
return Err(LexError {
|
||||
fallback: error,
|
||||
span: Span::call_site(),
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(Literal {
|
||||
fallback,
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Literal {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
Display::fmt(&self.fallback, formatter)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Literal {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
Debug::fmt(&self.fallback, formatter)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TokenStream {
|
||||
content: Vec<TokenTree>,
|
||||
}
|
||||
|
||||
impl TokenStream {
|
||||
pub fn new() -> Self {
|
||||
TokenStream {
|
||||
content: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.content.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for TokenStream {
|
||||
type Item = TokenTree;
|
||||
type IntoIter = token_stream::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
token_stream::IntoIter {
|
||||
iter: self.content.into_iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Extend<TokenStream> for TokenStream {
|
||||
fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I) {
|
||||
self.content.extend(streams.into_iter().flatten());
|
||||
}
|
||||
}
|
||||
|
||||
impl Extend<TokenTree> for TokenStream {
|
||||
fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, streams: I) {
|
||||
self.content.extend(streams);
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<TokenStream> for TokenStream {
|
||||
fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self {
|
||||
let content = streams.into_iter().flatten().collect();
|
||||
TokenStream { content }
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<TokenTree> for TokenStream {
|
||||
fn from_iter<I: IntoIterator<Item = TokenTree>>(streams: I) -> Self {
|
||||
let content = streams.into_iter().collect();
|
||||
TokenStream { content }
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for TokenStream {
|
||||
type Err = LexError;
|
||||
|
||||
fn from_str(string: &str) -> Result<Self, Self::Err> {
|
||||
let fallback = match proc_macro2::TokenStream::from_str(string) {
|
||||
Ok(token_stream) => token_stream,
|
||||
Err(error) => {
|
||||
return Err(LexError {
|
||||
fallback: error,
|
||||
span: Span::call_site(),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
fn convert_token_stream(stream: proc_macro2::TokenStream) -> TokenStream {
|
||||
TokenStream {
|
||||
content: stream.into_iter().map(convert_token_tree).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_token_tree(token: proc_macro2::TokenTree) -> TokenTree {
|
||||
match token {
|
||||
proc_macro2::TokenTree::Group(group) => TokenTree::Group(Group::new(
|
||||
group.delimiter(),
|
||||
convert_token_stream(group.stream()),
|
||||
)),
|
||||
proc_macro2::TokenTree::Ident(ident) => TokenTree::Ident(Ident {
|
||||
fallback: ident,
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}),
|
||||
proc_macro2::TokenTree::Punct(punct) => TokenTree::Punct(Punct {
|
||||
fallback: punct,
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}),
|
||||
proc_macro2::TokenTree::Literal(literal) => TokenTree::Literal(Literal {
|
||||
fallback: literal,
|
||||
span: Span::call_site(),
|
||||
identity: Identity::NOVEL,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(convert_token_stream(fallback))
|
||||
}
|
||||
}
|
||||
|
||||
fn display_tokens(tokens: &[TokenTree], formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut joint = false;
|
||||
for (i, token) in tokens.iter().enumerate() {
|
||||
if i != 0 && !joint {
|
||||
write!(formatter, " ")?;
|
||||
}
|
||||
joint = false;
|
||||
match token {
|
||||
TokenTree::Group(group) => Display::fmt(group, formatter),
|
||||
TokenTree::Ident(ident) => Display::fmt(ident, formatter),
|
||||
TokenTree::Punct(punct) => {
|
||||
joint = punct.spacing() == Spacing::Joint;
|
||||
Display::fmt(punct, formatter)
|
||||
}
|
||||
TokenTree::Literal(literal) => Display::fmt(literal, formatter),
|
||||
}?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl Display for TokenStream {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
display_tokens(&self.content, formatter)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for TokenStream {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("TokenStream ")?;
|
||||
formatter.debug_list().entries(&self.content).finish()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LexError {
|
||||
fallback: proc_macro2::LexError,
|
||||
span: Span,
|
||||
}
|
||||
|
||||
impl LexError {
|
||||
pub fn span(&self) -> Span {
|
||||
self.span
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for LexError {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
Debug::fmt(&self.fallback, formatter)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod token_stream {
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct IntoIter {
|
||||
pub(crate) iter: <Vec<TokenTree> as IntoIterator>::IntoIter,
|
||||
}
|
||||
|
||||
impl Iterator for IntoIter {
|
||||
type Item = TokenTree;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next()
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.iter.size_hint()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod extra {
|
||||
use crate::Span;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct DelimSpan {
|
||||
pub(crate) join: Span,
|
||||
pub(crate) open: Span,
|
||||
pub(crate) close: Span,
|
||||
}
|
||||
|
||||
impl DelimSpan {
|
||||
pub fn join(&self) -> Span {
|
||||
self.join
|
||||
}
|
||||
|
||||
pub fn open(&self) -> Span {
|
||||
self.open
|
||||
}
|
||||
|
||||
pub fn close(&self) -> Span {
|
||||
self.close
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
use std::str;
|
||||
|
||||
pub struct OutputBuffer {
|
||||
bytes: Vec<u8>,
|
||||
}
|
||||
|
||||
impl OutputBuffer {
|
||||
pub fn new() -> Self {
|
||||
OutputBuffer { bytes: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn write_u8(&mut self, value: u8) {
|
||||
self.bytes.push(value);
|
||||
}
|
||||
|
||||
pub fn write_u16(&mut self, value: u16) {
|
||||
self.bytes.extend_from_slice(&value.to_le_bytes());
|
||||
}
|
||||
|
||||
pub fn write_u32(&mut self, value: u32) {
|
||||
self.bytes.extend_from_slice(&value.to_le_bytes());
|
||||
}
|
||||
|
||||
pub fn write_str(&mut self, value: &str) {
|
||||
self.bytes.extend_from_slice(value.as_bytes());
|
||||
}
|
||||
|
||||
pub fn into_bytes(self) -> Vec<u8> {
|
||||
self.bytes
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InputBuffer<'a> {
|
||||
bytes: &'a [u8],
|
||||
}
|
||||
|
||||
impl<'a> InputBuffer<'a> {
|
||||
pub fn new(bytes: &'a [u8]) -> Self {
|
||||
InputBuffer { bytes }
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.bytes.is_empty()
|
||||
}
|
||||
|
||||
pub fn read_u8(&mut self) -> u8 {
|
||||
let (first, rest) = self.bytes.split_first().unwrap();
|
||||
self.bytes = rest;
|
||||
*first
|
||||
}
|
||||
|
||||
pub fn read_u16(&mut self) -> u16 {
|
||||
let (value, rest) = self.bytes.split_at(2);
|
||||
self.bytes = rest;
|
||||
u16::from_le_bytes([value[0], value[1]])
|
||||
}
|
||||
|
||||
pub fn read_u32(&mut self) -> u32 {
|
||||
let (value, rest) = self.bytes.split_at(4);
|
||||
self.bytes = rest;
|
||||
u32::from_le_bytes([value[0], value[1], value[2], value[3]])
|
||||
}
|
||||
|
||||
pub fn read_str(&mut self, len: usize) -> &'a str {
|
||||
let (string, rest) = self.bytes.split_at(len);
|
||||
self.bytes = rest;
|
||||
str::from_utf8(string).unwrap()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
pub enum Bytecode {}
|
||||
|
||||
impl Bytecode {
|
||||
pub const GROUP_PARENTHESIS: u8 = 0;
|
||||
pub const GROUP_BRACE: u8 = 1;
|
||||
pub const GROUP_BRACKET: u8 = 2;
|
||||
pub const GROUP_NONE: u8 = 3;
|
||||
pub const IDENT: u8 = 4;
|
||||
pub const PUNCT_ALONE: u8 = 5;
|
||||
pub const PUNCT_JOINT: u8 = 6;
|
||||
pub const LITERAL: u8 = 7;
|
||||
pub const LOAD_GROUP: u8 = 8;
|
||||
pub const LOAD_IDENT: u8 = 9;
|
||||
pub const LOAD_PUNCT: u8 = 10;
|
||||
pub const LOAD_LITERAL: u8 = 11;
|
||||
pub const SET_SPAN: u8 = 12;
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
pub mod buffer;
|
||||
pub mod bytecode;
|
||||
|
||||
use crate::watt::buffer::{InputBuffer, OutputBuffer};
|
||||
use crate::watt::bytecode::Bytecode;
|
||||
use crate::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
|
||||
use std::str::FromStr;
|
||||
|
||||
pub enum Kind {
|
||||
Group(Delimiter),
|
||||
Ident,
|
||||
Punct(Spacing),
|
||||
Literal,
|
||||
}
|
||||
|
||||
pub enum Identity {}
|
||||
|
||||
impl Identity {
|
||||
pub const RESPANNED: u32 = 1 << 31;
|
||||
pub const NOVEL: u32 = u32::MAX;
|
||||
}
|
||||
|
||||
impl Span {
|
||||
fn is_call_site(&self) -> bool {
|
||||
self.lo == 0 && self.hi == 0
|
||||
}
|
||||
}
|
||||
|
||||
fn post_increment(counter: &mut u32) -> impl FnMut() -> u32 + '_ {
|
||||
|| {
|
||||
let value = *counter;
|
||||
*counter += 1;
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load(buf: &mut InputBuffer) -> TokenStream {
|
||||
let mut span_counter = 1;
|
||||
let mut next_span = post_increment(&mut span_counter);
|
||||
let mut next_span = || {
|
||||
let next = next_span();
|
||||
Span { lo: next, hi: next }
|
||||
};
|
||||
|
||||
let [mut group_counter, mut ident_counter, mut punct_counter, mut literal_counter] = [0; 4];
|
||||
let mut next_group = post_increment(&mut group_counter);
|
||||
let mut next_ident = post_increment(&mut ident_counter);
|
||||
let mut next_punct = post_increment(&mut punct_counter);
|
||||
let mut next_literal = post_increment(&mut literal_counter);
|
||||
|
||||
let mut trees = Vec::new();
|
||||
while !buf.is_empty() {
|
||||
match match buf.read_u8() {
|
||||
Bytecode::GROUP_PARENTHESIS => Kind::Group(Delimiter::Parenthesis),
|
||||
Bytecode::GROUP_BRACE => Kind::Group(Delimiter::Brace),
|
||||
Bytecode::GROUP_BRACKET => Kind::Group(Delimiter::Bracket),
|
||||
Bytecode::GROUP_NONE => Kind::Group(Delimiter::None),
|
||||
Bytecode::IDENT => Kind::Ident,
|
||||
Bytecode::PUNCT_ALONE => Kind::Punct(Spacing::Alone),
|
||||
Bytecode::PUNCT_JOINT => Kind::Punct(Spacing::Joint),
|
||||
Bytecode::LITERAL => Kind::Literal,
|
||||
_ => unreachable!(),
|
||||
} {
|
||||
Kind::Group(delimiter) => {
|
||||
let len = buf.read_u32();
|
||||
let stream = trees.drain(trees.len() - len as usize..).collect();
|
||||
trees.push(TokenTree::Group(Group {
|
||||
delimiter,
|
||||
stream,
|
||||
span: next_span(),
|
||||
span_open: next_span(),
|
||||
span_close: next_span(),
|
||||
identity: next_group(),
|
||||
}));
|
||||
}
|
||||
Kind::Ident => {
|
||||
let len = buf.read_u16();
|
||||
let repr = buf.read_str(len as usize);
|
||||
let ident = if let Some(repr) = repr.strip_prefix("r#") {
|
||||
proc_macro2::Ident::new_raw(repr, proc_macro2::Span::call_site())
|
||||
} else {
|
||||
proc_macro2::Ident::new(repr, proc_macro2::Span::call_site())
|
||||
};
|
||||
trees.push(TokenTree::Ident(Ident {
|
||||
fallback: ident,
|
||||
span: next_span(),
|
||||
identity: next_ident(),
|
||||
}));
|
||||
}
|
||||
Kind::Punct(spacing) => {
|
||||
let ch = buf.read_u8();
|
||||
assert!(ch.is_ascii());
|
||||
let punct = proc_macro2::Punct::new(ch as char, spacing);
|
||||
trees.push(TokenTree::Punct(Punct {
|
||||
fallback: punct,
|
||||
span: next_span(),
|
||||
identity: next_punct(),
|
||||
}));
|
||||
}
|
||||
Kind::Literal => {
|
||||
let len = buf.read_u16();
|
||||
let repr = buf.read_str(len as usize);
|
||||
let literal = proc_macro2::Literal::from_str(repr).unwrap();
|
||||
trees.push(TokenTree::Literal(Literal {
|
||||
fallback: literal,
|
||||
span: next_span(),
|
||||
identity: next_literal(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TokenStream { content: trees }
|
||||
}
|
||||
|
||||
pub fn linearize(tokens: TokenStream) -> Vec<u8> {
|
||||
let mut buf = OutputBuffer::new();
|
||||
for token in &tokens.content {
|
||||
linearize_token(token, &mut buf);
|
||||
}
|
||||
buf.into_bytes()
|
||||
}
|
||||
|
||||
fn linearize_token(token: &TokenTree, buf: &mut OutputBuffer) {
|
||||
let needs_span;
|
||||
match token {
|
||||
TokenTree::Group(group) => {
|
||||
if group.identity < Identity::NOVEL {
|
||||
buf.write_u8(Bytecode::LOAD_GROUP);
|
||||
buf.write_u32(group.identity & !Identity::RESPANNED);
|
||||
needs_span = group.identity >= Identity::RESPANNED;
|
||||
} else {
|
||||
let len = group.stream.len();
|
||||
assert!(len <= u32::MAX as usize);
|
||||
for token in &group.stream {
|
||||
linearize_token(token, buf);
|
||||
}
|
||||
buf.write_u8(match group.delimiter {
|
||||
Delimiter::Parenthesis => Bytecode::GROUP_PARENTHESIS,
|
||||
Delimiter::Brace => Bytecode::GROUP_BRACE,
|
||||
Delimiter::Bracket => Bytecode::GROUP_BRACKET,
|
||||
Delimiter::None => Bytecode::GROUP_NONE,
|
||||
});
|
||||
buf.write_u32(len as u32);
|
||||
needs_span = !group.span.is_call_site();
|
||||
}
|
||||
}
|
||||
TokenTree::Ident(ident) => {
|
||||
if ident.identity < Identity::NOVEL {
|
||||
buf.write_u8(Bytecode::LOAD_IDENT);
|
||||
buf.write_u32(ident.identity & !Identity::RESPANNED);
|
||||
needs_span = ident.identity >= Identity::RESPANNED;
|
||||
} else {
|
||||
buf.write_u8(Bytecode::IDENT);
|
||||
let repr = ident.to_string();
|
||||
assert!(repr.len() <= u16::MAX as usize);
|
||||
buf.write_u16(repr.len() as u16);
|
||||
buf.write_str(&repr);
|
||||
linearize_span(ident.span, buf);
|
||||
needs_span = false;
|
||||
}
|
||||
}
|
||||
TokenTree::Punct(punct) => {
|
||||
if punct.identity < Identity::NOVEL {
|
||||
buf.write_u8(Bytecode::LOAD_PUNCT);
|
||||
buf.write_u32(punct.identity & !Identity::RESPANNED);
|
||||
needs_span = punct.identity >= Identity::RESPANNED;
|
||||
} else {
|
||||
buf.write_u8(match punct.spacing() {
|
||||
Spacing::Alone => Bytecode::PUNCT_ALONE,
|
||||
Spacing::Joint => Bytecode::PUNCT_JOINT,
|
||||
});
|
||||
let ch = punct.as_char();
|
||||
assert!(ch.is_ascii());
|
||||
buf.write_u8(ch as u8);
|
||||
needs_span = !punct.span.is_call_site();
|
||||
}
|
||||
}
|
||||
TokenTree::Literal(literal) => {
|
||||
if literal.identity < Identity::NOVEL {
|
||||
buf.write_u8(Bytecode::LOAD_LITERAL);
|
||||
buf.write_u32(literal.identity & !Identity::RESPANNED);
|
||||
needs_span = literal.identity >= Identity::RESPANNED;
|
||||
} else {
|
||||
buf.write_u8(Bytecode::LITERAL);
|
||||
let repr = literal.to_string();
|
||||
assert!(repr.len() <= u16::MAX as usize);
|
||||
buf.write_u16(repr.len() as u16);
|
||||
buf.write_str(&repr);
|
||||
needs_span = !literal.span.is_call_site();
|
||||
}
|
||||
}
|
||||
}
|
||||
if needs_span {
|
||||
buf.write_u8(Bytecode::SET_SPAN);
|
||||
linearize_span(token.span(), buf);
|
||||
}
|
||||
}
|
||||
|
||||
fn linearize_span(span: Span, buf: &mut OutputBuffer) {
|
||||
buf.write_u32(span.lo);
|
||||
buf.write_u32(span.hi);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
[package]
|
||||
name = "serde_derive"
|
||||
version = "1.0.172"
|
||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||
categories = ["no-std", "no-std::no-alloc"]
|
||||
description = "Implementation of #[derive(Serialize, Deserialize)]"
|
||||
documentation = "https://serde.rs/derive.html"
|
||||
edition = "2015"
|
||||
homepage = "https://serde.rs"
|
||||
include = ["serde_derive-x86_64-unknown-linux-gnu", "src"]
|
||||
keywords = ["serde", "serialization", "no_std", "derive"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
readme = "crates-io.md"
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
rust-version = "1.56"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
deserialize_in_place = []
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[target.'cfg(not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")))'.dependencies]
|
||||
proc-macro2 = "1"
|
||||
quote = "1"
|
||||
syn = "2.0.25"
|
||||
|
||||
[dev-dependencies]
|
||||
serde = { version = "1", path = "../../serde" }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[workspace]
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../LICENSE-APACHE
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../LICENSE-MIT
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../README.md
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../crates-io.md
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../serde_derive/src/bound.rs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../proc-macro2/src/watt/buffer.rs
|
||||
@@ -0,0 +1 @@
|
||||
../../proc-macro2/src/watt/bytecode.rs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../serde_derive/src/de.rs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../serde_derive/src/dummy.rs
|
||||
@@ -0,0 +1 @@
|
||||
../../../serde_derive/src/fragment.rs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../serde_derive/src/internals/
|
||||
@@ -0,0 +1,25 @@
|
||||
//! This crate provides Serde's two derive macros.
|
||||
//!
|
||||
//! ```edition2021
|
||||
//! # use serde_derive::{Deserialize, Serialize};
|
||||
//! #
|
||||
//! #[derive(Serialize, Deserialize)]
|
||||
//! # struct S;
|
||||
//! #
|
||||
//! # fn main() {}
|
||||
//! ```
|
||||
//!
|
||||
//! Please refer to [https://serde.rs/derive.html] for how to set this up.
|
||||
//!
|
||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.172")]
|
||||
#![allow(unknown_lints, bare_trait_objects)]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
#[cfg(not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")))]
|
||||
include!("lib_from_source.rs");
|
||||
|
||||
#[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))]
|
||||
include!("lib_precompiled.rs");
|
||||
@@ -0,0 +1,39 @@
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
#[macro_use]
|
||||
extern crate syn;
|
||||
|
||||
extern crate proc_macro2;
|
||||
|
||||
mod internals;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use syn::DeriveInput;
|
||||
|
||||
#[macro_use]
|
||||
mod bound;
|
||||
#[macro_use]
|
||||
mod fragment;
|
||||
|
||||
mod de;
|
||||
mod dummy;
|
||||
mod pretend;
|
||||
mod ser;
|
||||
mod this;
|
||||
mod try;
|
||||
|
||||
#[proc_macro_derive(Serialize, attributes(serde))]
|
||||
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
||||
let mut input = parse_macro_input!(input as DeriveInput);
|
||||
ser::expand_derive_serialize(&mut input)
|
||||
.unwrap_or_else(syn::Error::into_compile_error)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(Deserialize, attributes(serde))]
|
||||
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
||||
let mut input = parse_macro_input!(input as DeriveInput);
|
||||
de::expand_derive_deserialize(&mut input)
|
||||
.unwrap_or_else(syn::Error::into_compile_error)
|
||||
.into()
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
mod buffer;
|
||||
mod bytecode;
|
||||
|
||||
use crate::buffer::{InputBuffer, OutputBuffer};
|
||||
use crate::bytecode::Bytecode;
|
||||
use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
|
||||
use std::io::{Read, Write};
|
||||
use std::iter::FromIterator;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[proc_macro_derive(Serialize, attributes(serde))]
|
||||
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
||||
derive(0, input)
|
||||
}
|
||||
|
||||
#[proc_macro_derive(Deserialize, attributes(serde))]
|
||||
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
||||
derive(1 + cfg!(feature = "deserialize_in_place") as u8, input)
|
||||
}
|
||||
|
||||
fn derive(select: u8, input: TokenStream) -> TokenStream {
|
||||
let mut memory = TokenMemory::default();
|
||||
let mut buf = OutputBuffer::new();
|
||||
buf.write_u8(select);
|
||||
|
||||
memory.spans.push(Span::call_site());
|
||||
for token in input {
|
||||
memory.linearize_token(token, &mut buf);
|
||||
}
|
||||
|
||||
let path = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/serde_derive-x86_64-unknown-linux-gnu",
|
||||
);
|
||||
let mut child = Command::new(path)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("failed to spawn process");
|
||||
|
||||
let mut stdin = child.stdin.take().unwrap();
|
||||
let mut buf = buf.into_bytes();
|
||||
stdin.write_all(&buf).unwrap();
|
||||
drop(stdin);
|
||||
|
||||
let mut stdout = child.stdout.take().unwrap();
|
||||
buf.clear();
|
||||
stdout.read_to_end(&mut buf).unwrap();
|
||||
|
||||
let mut buf = InputBuffer::new(&buf);
|
||||
memory.receive(&mut buf)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct TokenMemory {
|
||||
spans: Vec<Span>,
|
||||
groups: Vec<Group>,
|
||||
idents: Vec<Ident>,
|
||||
puncts: Vec<Punct>,
|
||||
literals: Vec<Literal>,
|
||||
}
|
||||
|
||||
enum Kind {
|
||||
Group(Delimiter),
|
||||
Ident,
|
||||
Punct(Spacing),
|
||||
Literal,
|
||||
}
|
||||
|
||||
impl TokenMemory {
|
||||
// Depth-first post-order traversal.
|
||||
fn linearize_token(&mut self, token: TokenTree, buf: &mut OutputBuffer) {
|
||||
match token {
|
||||
TokenTree::Group(group) => {
|
||||
let mut len = 0usize;
|
||||
for token in group.stream() {
|
||||
self.linearize_token(token, buf);
|
||||
len += 1;
|
||||
}
|
||||
assert!(len <= u32::MAX as usize);
|
||||
buf.write_u8(match group.delimiter() {
|
||||
Delimiter::Parenthesis => Bytecode::GROUP_PARENTHESIS,
|
||||
Delimiter::Brace => Bytecode::GROUP_BRACE,
|
||||
Delimiter::Bracket => Bytecode::GROUP_BRACKET,
|
||||
Delimiter::None => Bytecode::GROUP_NONE,
|
||||
});
|
||||
buf.write_u32(len as u32);
|
||||
self.spans
|
||||
.extend([group.span(), group.span_open(), group.span_close()]);
|
||||
self.groups.push(group);
|
||||
}
|
||||
TokenTree::Ident(ident) => {
|
||||
buf.write_u8(Bytecode::IDENT);
|
||||
let repr = ident.to_string();
|
||||
assert!(repr.len() <= u16::MAX as usize);
|
||||
buf.write_u16(repr.len() as u16);
|
||||
buf.write_str(&repr);
|
||||
self.spans.push(ident.span());
|
||||
self.idents.push(ident);
|
||||
}
|
||||
TokenTree::Punct(punct) => {
|
||||
buf.write_u8(match punct.spacing() {
|
||||
Spacing::Alone => Bytecode::PUNCT_ALONE,
|
||||
Spacing::Joint => Bytecode::PUNCT_JOINT,
|
||||
});
|
||||
let ch = punct.as_char();
|
||||
assert!(ch.is_ascii());
|
||||
buf.write_u8(ch as u8);
|
||||
self.spans.push(punct.span());
|
||||
self.puncts.push(punct);
|
||||
}
|
||||
TokenTree::Literal(literal) => {
|
||||
buf.write_u8(Bytecode::LITERAL);
|
||||
let repr = literal.to_string();
|
||||
assert!(repr.len() <= u16::MAX as usize);
|
||||
buf.write_u16(repr.len() as u16);
|
||||
buf.write_str(&repr);
|
||||
self.spans.push(literal.span());
|
||||
self.literals.push(literal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn receive(&self, buf: &mut InputBuffer) -> TokenStream {
|
||||
let mut trees = Vec::new();
|
||||
while !buf.is_empty() {
|
||||
match match buf.read_u8() {
|
||||
Bytecode::GROUP_PARENTHESIS => Kind::Group(Delimiter::Parenthesis),
|
||||
Bytecode::GROUP_BRACE => Kind::Group(Delimiter::Brace),
|
||||
Bytecode::GROUP_BRACKET => Kind::Group(Delimiter::Bracket),
|
||||
Bytecode::GROUP_NONE => Kind::Group(Delimiter::None),
|
||||
Bytecode::IDENT => Kind::Ident,
|
||||
Bytecode::PUNCT_ALONE => Kind::Punct(Spacing::Alone),
|
||||
Bytecode::PUNCT_JOINT => Kind::Punct(Spacing::Joint),
|
||||
Bytecode::LITERAL => Kind::Literal,
|
||||
Bytecode::LOAD_GROUP => {
|
||||
let identity = buf.read_u32();
|
||||
let group = self.groups[identity as usize].clone();
|
||||
trees.push(TokenTree::Group(group));
|
||||
continue;
|
||||
}
|
||||
Bytecode::LOAD_IDENT => {
|
||||
let identity = buf.read_u32();
|
||||
let ident = self.idents[identity as usize].clone();
|
||||
trees.push(TokenTree::Ident(ident));
|
||||
continue;
|
||||
}
|
||||
Bytecode::LOAD_PUNCT => {
|
||||
let identity = buf.read_u32();
|
||||
let punct = self.puncts[identity as usize].clone();
|
||||
trees.push(TokenTree::Punct(punct));
|
||||
continue;
|
||||
}
|
||||
Bytecode::LOAD_LITERAL => {
|
||||
let identity = buf.read_u32();
|
||||
let literal = self.literals[identity as usize].clone();
|
||||
trees.push(TokenTree::Literal(literal));
|
||||
continue;
|
||||
}
|
||||
Bytecode::SET_SPAN => {
|
||||
trees.last_mut().unwrap().set_span(self.read_span(buf));
|
||||
continue;
|
||||
}
|
||||
_ => unreachable!(),
|
||||
} {
|
||||
Kind::Group(delimiter) => {
|
||||
let len = buf.read_u32();
|
||||
let stream = trees.drain(trees.len() - len as usize..).collect();
|
||||
let group = Group::new(delimiter, stream);
|
||||
trees.push(TokenTree::Group(group));
|
||||
}
|
||||
Kind::Ident => {
|
||||
let len = buf.read_u16();
|
||||
let repr = buf.read_str(len as usize);
|
||||
let span = self.read_span(buf);
|
||||
let ident = if let Some(repr) = repr.strip_prefix("r#") {
|
||||
Ident::new_raw(repr, span)
|
||||
} else {
|
||||
Ident::new(repr, span)
|
||||
};
|
||||
trees.push(TokenTree::Ident(ident));
|
||||
}
|
||||
Kind::Punct(spacing) => {
|
||||
let ch = buf.read_u8();
|
||||
assert!(ch.is_ascii());
|
||||
let punct = Punct::new(ch as char, spacing);
|
||||
trees.push(TokenTree::Punct(punct));
|
||||
}
|
||||
Kind::Literal => {
|
||||
let len = buf.read_u16();
|
||||
let repr = buf.read_str(len as usize);
|
||||
let literal = Literal::from_str(repr).unwrap();
|
||||
trees.push(TokenTree::Literal(literal));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TokenStream::from_iter(trees)
|
||||
}
|
||||
|
||||
fn read_span(&self, buf: &mut InputBuffer) -> Span {
|
||||
let lo = buf.read_u32();
|
||||
let hi = buf.read_u32();
|
||||
let span = self.spans[lo as usize];
|
||||
if lo == hi {
|
||||
span
|
||||
} else {
|
||||
#[cfg(any())] // FIXME
|
||||
return span.join(self.spans[hi as usize]).unwrap_or(span);
|
||||
span
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../serde_derive/src/pretend.rs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../serde_derive/src/ser.rs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../serde_derive/src/this.rs
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../serde_derive/src/try.rs
|
||||
+16
-12
@@ -1,28 +1,32 @@
|
||||
[package]
|
||||
name = "serde"
|
||||
version = "1.0.130" # remember to update html_root_url and serde_derive dependency
|
||||
version = "1.0.172" # remember to update html_root_url and serde_derive dependency
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "A generic serialization/deserialization framework"
|
||||
homepage = "https://serde.rs"
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
documentation = "https://docs.serde.rs/serde/"
|
||||
keywords = ["serde", "serialization", "no_std"]
|
||||
categories = ["encoding"]
|
||||
readme = "crates-io.md"
|
||||
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||
build = "build.rs"
|
||||
categories = ["encoding", "no-std", "no-std::no-alloc"]
|
||||
description = "A generic serialization/deserialization framework"
|
||||
documentation = "https://docs.rs/serde"
|
||||
homepage = "https://serde.rs"
|
||||
keywords = ["serde", "serialization", "no_std"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
readme = "crates-io.md"
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
rust-version = "1.19"
|
||||
|
||||
[dependencies]
|
||||
serde_derive = { version = "=1.0.130", optional = true, path = "../serde_derive" }
|
||||
serde_derive = { version = "=1.0.172", optional = true, path = "../serde_derive" }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_derive = { version = "1.0", path = "../serde_derive" }
|
||||
serde_derive = { version = "1", path = "../serde_derive" }
|
||||
|
||||
[lib]
|
||||
doc-scrape-examples = false
|
||||
|
||||
[package.metadata.playground]
|
||||
features = ["derive", "rc"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["derive"]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
|
||||
|
||||
+51
-37
@@ -6,6 +6,8 @@ use std::str::{self, FromStr};
|
||||
// opening a GitHub issue if your build environment requires some way to enable
|
||||
// these cfgs other than by executing our build script.
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
||||
let minor = match rustc_minor_version() {
|
||||
Some(minor) => minor,
|
||||
None => return,
|
||||
@@ -17,37 +19,38 @@ fn main() {
|
||||
// std::collections::Bound was stabilized in Rust 1.17
|
||||
// but it was moved to core::ops later in Rust 1.26:
|
||||
// https://doc.rust-lang.org/core/ops/enum.Bound.html
|
||||
if minor >= 26 {
|
||||
println!("cargo:rustc-cfg=ops_bound");
|
||||
} else if minor >= 17 && cfg!(feature = "std") {
|
||||
println!("cargo:rustc-cfg=collections_bound");
|
||||
if minor < 26 {
|
||||
println!("cargo:rustc-cfg=no_ops_bound");
|
||||
if minor < 17 {
|
||||
println!("cargo:rustc-cfg=no_collections_bound");
|
||||
}
|
||||
}
|
||||
|
||||
// core::cmp::Reverse stabilized in Rust 1.19:
|
||||
// https://doc.rust-lang.org/stable/core/cmp/struct.Reverse.html
|
||||
if minor >= 19 {
|
||||
println!("cargo:rustc-cfg=core_reverse");
|
||||
if minor < 19 {
|
||||
println!("cargo:rustc-cfg=no_core_reverse");
|
||||
}
|
||||
|
||||
// CString::into_boxed_c_str and PathBuf::into_boxed_path stabilized in Rust 1.20:
|
||||
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
|
||||
// https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.into_boxed_path
|
||||
if minor >= 20 {
|
||||
println!("cargo:rustc-cfg=de_boxed_c_str");
|
||||
println!("cargo:rustc-cfg=de_boxed_path");
|
||||
if minor < 20 {
|
||||
println!("cargo:rustc-cfg=no_de_boxed_c_str");
|
||||
println!("cargo:rustc-cfg=no_de_boxed_path");
|
||||
}
|
||||
|
||||
// From<Box<T>> for Rc<T> / Arc<T> stabilized in Rust 1.21:
|
||||
// https://doc.rust-lang.org/std/rc/struct.Rc.html#impl-From<Box<T>>
|
||||
// https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-From<Box<T>>
|
||||
if minor >= 21 {
|
||||
println!("cargo:rustc-cfg=de_rc_dst");
|
||||
if minor < 21 {
|
||||
println!("cargo:rustc-cfg=no_de_rc_dst");
|
||||
}
|
||||
|
||||
// Duration available in core since Rust 1.25:
|
||||
// https://blog.rust-lang.org/2018/03/29/Rust-1.25.html#library-stabilizations
|
||||
if minor >= 25 {
|
||||
println!("cargo:rustc-cfg=core_duration");
|
||||
if minor < 25 {
|
||||
println!("cargo:rustc-cfg=no_core_duration");
|
||||
}
|
||||
|
||||
// 128-bit integers stabilized in Rust 1.26:
|
||||
@@ -56,56 +59,67 @@ fn main() {
|
||||
// Disabled on Emscripten targets before Rust 1.40 since
|
||||
// Emscripten did not support 128-bit integers until Rust 1.40
|
||||
// (https://github.com/rust-lang/rust/pull/65251)
|
||||
if minor >= 26 && (!emscripten || minor >= 40) {
|
||||
println!("cargo:rustc-cfg=integer128");
|
||||
if minor < 26 || emscripten && minor < 40 {
|
||||
println!("cargo:rustc-cfg=no_integer128");
|
||||
}
|
||||
|
||||
// Inclusive ranges methods stabilized in Rust 1.27:
|
||||
// https://github.com/rust-lang/rust/pull/50758
|
||||
// Also Iterator::try_for_each:
|
||||
// https://blog.rust-lang.org/2018/06/21/Rust-1.27.html#library-stabilizations
|
||||
if minor >= 27 {
|
||||
println!("cargo:rustc-cfg=range_inclusive");
|
||||
println!("cargo:rustc-cfg=iterator_try_fold");
|
||||
if minor < 27 {
|
||||
println!("cargo:rustc-cfg=no_range_inclusive");
|
||||
println!("cargo:rustc-cfg=no_iterator_try_fold");
|
||||
}
|
||||
|
||||
// Non-zero integers stabilized in Rust 1.28:
|
||||
// https://blog.rust-lang.org/2018/08/02/Rust-1.28.html#library-stabilizations
|
||||
if minor >= 28 {
|
||||
println!("cargo:rustc-cfg=num_nonzero");
|
||||
}
|
||||
|
||||
// Current minimum supported version of serde_derive crate is Rust 1.31.
|
||||
if minor >= 31 {
|
||||
println!("cargo:rustc-cfg=serde_derive");
|
||||
if minor < 28 {
|
||||
println!("cargo:rustc-cfg=no_num_nonzero");
|
||||
}
|
||||
|
||||
// TryFrom, Atomic types, non-zero signed integers, and SystemTime::checked_add
|
||||
// stabilized in Rust 1.34:
|
||||
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto
|
||||
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#library-stabilizations
|
||||
if minor >= 34 {
|
||||
println!("cargo:rustc-cfg=core_try_from");
|
||||
println!("cargo:rustc-cfg=num_nonzero_signed");
|
||||
println!("cargo:rustc-cfg=systemtime_checked_add");
|
||||
if minor < 34 {
|
||||
println!("cargo:rustc-cfg=no_core_try_from");
|
||||
println!("cargo:rustc-cfg=no_num_nonzero_signed");
|
||||
println!("cargo:rustc-cfg=no_systemtime_checked_add");
|
||||
println!("cargo:rustc-cfg=no_relaxed_trait_bounds");
|
||||
}
|
||||
|
||||
// Whitelist of archs that support std::sync::atomic module. Ideally we
|
||||
// would use #[cfg(target_has_atomic = "...")] but it is not stable yet.
|
||||
// Instead this is based on rustc's src/librustc_target/spec/*.rs.
|
||||
// Current minimum supported version of serde_derive crate is Rust 1.56.
|
||||
if minor < 56 {
|
||||
println!("cargo:rustc-cfg=no_serde_derive");
|
||||
}
|
||||
|
||||
// Support for #[cfg(target_has_atomic = "...")] stabilized in Rust 1.60.
|
||||
if minor < 60 {
|
||||
println!("cargo:rustc-cfg=no_target_has_atomic");
|
||||
// Allowlist of archs that support std::sync::atomic module. This is
|
||||
// based on rustc's compiler/rustc_target/src/spec/*.rs.
|
||||
let has_atomic64 = target.starts_with("x86_64")
|
||||
|| target.starts_with("i686")
|
||||
|| target.starts_with("aarch64")
|
||||
|| target.starts_with("powerpc64")
|
||||
|| target.starts_with("sparc64")
|
||||
|| target.starts_with("mips64el");
|
||||
|| target.starts_with("mips64el")
|
||||
|| target.starts_with("riscv64");
|
||||
let has_atomic32 = has_atomic64 || emscripten;
|
||||
if has_atomic64 {
|
||||
println!("cargo:rustc-cfg=std_atomic64");
|
||||
if minor < 34 || !has_atomic64 {
|
||||
println!("cargo:rustc-cfg=no_std_atomic64");
|
||||
}
|
||||
if has_atomic32 {
|
||||
println!("cargo:rustc-cfg=std_atomic");
|
||||
if minor < 34 || !has_atomic32 {
|
||||
println!("cargo:rustc-cfg=no_std_atomic");
|
||||
}
|
||||
}
|
||||
|
||||
// Support for core::ffi::CStr and alloc::ffi::CString stabilized in Rust 1.64.
|
||||
// https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html#c-compatible-ffi-types-in-core-and-alloc
|
||||
if minor < 64 {
|
||||
println!("cargo:rustc-cfg=no_core_cstr");
|
||||
}
|
||||
}
|
||||
|
||||
fn rustc_minor_version() -> Option<u32> {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
use lib::fmt::{self, Write};
|
||||
use lib::str;
|
||||
|
||||
pub(super) struct Buf<'a> {
|
||||
bytes: &'a mut [u8],
|
||||
offset: usize,
|
||||
}
|
||||
|
||||
impl<'a> Buf<'a> {
|
||||
pub fn new(bytes: &'a mut [u8]) -> Self {
|
||||
Buf { bytes, offset: 0 }
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
let slice = &self.bytes[..self.offset];
|
||||
unsafe { str::from_utf8_unchecked(slice) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Write for Buf<'a> {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
if self.offset + s.len() > self.bytes.len() {
|
||||
Err(fmt::Error)
|
||||
} else {
|
||||
self.bytes[self.offset..self.offset + s.len()].copy_from_slice(s.as_bytes());
|
||||
self.offset += s.len();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,12 @@ use de::{
|
||||
/// any type, except that it does not store any information about the data that
|
||||
/// gets deserialized.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use std::fmt;
|
||||
/// use std::marker::PhantomData;
|
||||
///
|
||||
/// ```edition2021
|
||||
/// use serde::de::{
|
||||
/// self, Deserialize, DeserializeSeed, Deserializer, IgnoredAny, SeqAccess, Visitor,
|
||||
/// };
|
||||
/// use std::fmt;
|
||||
/// use std::marker::PhantomData;
|
||||
///
|
||||
/// /// A seed that can be used to deserialize only the `n`th element of a sequence
|
||||
/// /// while efficiently discarding elements of any type before or after index `n`.
|
||||
@@ -108,7 +107,7 @@ use de::{
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
pub struct IgnoredAny;
|
||||
|
||||
impl<'de> Visitor<'de> for IgnoredAny {
|
||||
@@ -228,7 +227,7 @@ impl<'de> Visitor<'de> for IgnoredAny {
|
||||
where
|
||||
A: EnumAccess<'de>,
|
||||
{
|
||||
data.variant::<IgnoredAny>()?.1.newtype_variant()
|
||||
try!(data.variant::<IgnoredAny>()).1.newtype_variant()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+567
-221
File diff suppressed because it is too large
Load Diff
+69
-49
@@ -30,7 +30,7 @@
|
||||
//! # The Deserializer trait
|
||||
//!
|
||||
//! [`Deserializer`] implementations are provided by third-party crates, for
|
||||
//! example [`serde_json`], [`serde_yaml`] and [`bincode`].
|
||||
//! example [`serde_json`], [`serde_yaml`] and [`postcard`].
|
||||
//!
|
||||
//! A partial list of well-maintained formats is given on the [Serde
|
||||
//! website][data formats].
|
||||
@@ -104,7 +104,7 @@
|
||||
//! [`Deserialize`]: ../trait.Deserialize.html
|
||||
//! [`Deserializer`]: ../trait.Deserializer.html
|
||||
//! [`LinkedHashMap<K, V>`]: https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html
|
||||
//! [`bincode`]: https://github.com/servo/bincode
|
||||
//! [`postcard`]: https://github.com/jamesmunns/postcard
|
||||
//! [`linked-hash-map`]: https://crates.io/crates/linked-hash-map
|
||||
//! [`serde_derive`]: https://crates.io/crates/serde_derive
|
||||
//! [`serde_json`]: https://github.com/serde-rs/json
|
||||
@@ -118,6 +118,8 @@ use lib::*;
|
||||
|
||||
pub mod value;
|
||||
|
||||
#[cfg(not(no_integer128))]
|
||||
mod format;
|
||||
mod ignored_any;
|
||||
mod impls;
|
||||
mod utf8;
|
||||
@@ -160,7 +162,7 @@ macro_rules! declare_error_trait {
|
||||
///
|
||||
/// The message should not be capitalized and should not end with a period.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::str::FromStr;
|
||||
/// #
|
||||
/// # struct IpAddr;
|
||||
@@ -305,7 +307,7 @@ declare_error_trait!(Error: Sized + Debug + Display);
|
||||
/// This is used as an argument to the `invalid_type`, `invalid_value`, and
|
||||
/// `invalid_length` methods of the `Error` trait to build error messages.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::fmt;
|
||||
/// #
|
||||
/// # use serde::de::{self, Unexpected, Visitor};
|
||||
@@ -430,10 +432,9 @@ impl<'a> fmt::Display for Unexpected<'a> {
|
||||
/// Within the context of a `Visitor` implementation, the `Visitor` itself
|
||||
/// (`&self`) is an implementation of this trait.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use std::fmt;
|
||||
/// #
|
||||
/// ```edition2021
|
||||
/// # use serde::de::{self, Unexpected, Visitor};
|
||||
/// # use std::fmt;
|
||||
/// #
|
||||
/// # struct Example;
|
||||
/// #
|
||||
@@ -455,7 +456,7 @@ impl<'a> fmt::Display for Unexpected<'a> {
|
||||
///
|
||||
/// Outside of a `Visitor`, `&"..."` can be used.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::de::{self, Unexpected};
|
||||
/// #
|
||||
/// # fn example<E>() -> Result<(), E>
|
||||
@@ -463,7 +464,10 @@ impl<'a> fmt::Display for Unexpected<'a> {
|
||||
/// # E: de::Error,
|
||||
/// # {
|
||||
/// # let v = true;
|
||||
/// return Err(de::Error::invalid_type(Unexpected::Bool(v), &"a negative integer"));
|
||||
/// return Err(de::Error::invalid_type(
|
||||
/// Unexpected::Bool(v),
|
||||
/// &"a negative integer",
|
||||
/// ));
|
||||
/// # }
|
||||
/// ```
|
||||
pub trait Expected {
|
||||
@@ -499,8 +503,8 @@ impl<'a> Display for Expected + 'a {
|
||||
/// by Serde.
|
||||
///
|
||||
/// Serde provides `Deserialize` implementations for many Rust primitive and
|
||||
/// standard library types. The complete list is [here][de]. All of these can
|
||||
/// be deserialized using Serde out of the box.
|
||||
/// standard library types. The complete list is [here][crate::de]. All of these
|
||||
/// can be deserialized using Serde out of the box.
|
||||
///
|
||||
/// Additionally, Serde provides a procedural macro called `serde_derive` to
|
||||
/// automatically generate `Deserialize` implementations for structs and enums
|
||||
@@ -516,7 +520,6 @@ impl<'a> Display for Expected + 'a {
|
||||
/// `LinkedHashMap<K, V>` type that is deserializable by Serde because the crate
|
||||
/// provides an implementation of `Deserialize` for it.
|
||||
///
|
||||
/// [de]: https://docs.serde.rs/serde/de/index.html
|
||||
/// [derive]: https://serde.rs/derive.html
|
||||
/// [impl-deserialize]: https://serde.rs/impl-deserialize.html
|
||||
///
|
||||
@@ -563,7 +566,7 @@ pub trait Deserialize<'de>: Sized {
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
// Default implementation just delegates to `deserialize` impl.
|
||||
*place = Deserialize::deserialize(deserializer)?;
|
||||
*place = try!(Deserialize::deserialize(deserializer));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -576,7 +579,7 @@ pub trait Deserialize<'de>: Sized {
|
||||
/// from the input string, but a `from_reader` function may only deserialize
|
||||
/// owned data.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::de::{Deserialize, DeserializeOwned};
|
||||
/// # use std::io::{Read, Result};
|
||||
/// #
|
||||
@@ -615,7 +618,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
||||
///
|
||||
/// The canonical API for stateless deserialization looks like this:
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Deserialize;
|
||||
/// #
|
||||
/// # enum Error {}
|
||||
@@ -629,7 +632,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
||||
/// Adjusting an API like this to support stateful deserialization is a matter
|
||||
/// of accepting a seed as input:
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::de::DeserializeSeed;
|
||||
/// #
|
||||
/// # enum Error {}
|
||||
@@ -662,12 +665,11 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
||||
/// into it. This requires stateful deserialization using the `DeserializeSeed`
|
||||
/// trait.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor};
|
||||
/// use std::fmt;
|
||||
/// use std::marker::PhantomData;
|
||||
///
|
||||
/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor};
|
||||
///
|
||||
/// // A DeserializeSeed implementation that uses stateful deserialization to
|
||||
/// // append array elements onto the end of an existing vector. The preexisting
|
||||
/// // state ("seed") in this case is the Vec<T>. The `deserialize` method of
|
||||
@@ -706,6 +708,11 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
||||
/// where
|
||||
/// A: SeqAccess<'de>,
|
||||
/// {
|
||||
/// // Decrease the number of reallocations if there are many elements
|
||||
/// if let Some(size_hint) = seq.size_hint() {
|
||||
/// self.0.reserve(size_hint);
|
||||
/// }
|
||||
///
|
||||
/// // Visit each element in the inner array and push it onto
|
||||
/// // the existing vector.
|
||||
/// while let Some(elem) = seq.next_element()? {
|
||||
@@ -855,10 +862,10 @@ where
|
||||
/// The `Deserializer` trait supports two entry point styles which enables
|
||||
/// different kinds of deserialization.
|
||||
///
|
||||
/// 1. The `deserialize` method. Self-describing data formats like JSON are able
|
||||
/// to look at the serialized data and tell what it represents. For example
|
||||
/// the JSON deserializer may see an opening curly brace (`{`) and know that
|
||||
/// it is seeing a map. If the data format supports
|
||||
/// 1. The `deserialize_any` method. Self-describing data formats like JSON are
|
||||
/// able to look at the serialized data and tell what it represents. For
|
||||
/// example the JSON deserializer may see an opening curly brace (`{`) and
|
||||
/// know that it is seeing a map. If the data format supports
|
||||
/// `Deserializer::deserialize_any`, it will drive the Visitor using whatever
|
||||
/// type it sees in the input. JSON uses this approach when deserializing
|
||||
/// `serde_json::Value` which is an enum that can represent any JSON
|
||||
@@ -867,7 +874,7 @@ where
|
||||
/// `Deserializer::deserialize_any`.
|
||||
///
|
||||
/// 2. The various `deserialize_*` methods. Non-self-describing formats like
|
||||
/// Bincode need to be told what is in the input in order to deserialize it.
|
||||
/// Postcard need to be told what is in the input in order to deserialize it.
|
||||
/// The `deserialize_*` methods are hints to the deserializer for how to
|
||||
/// interpret the next piece of input. Non-self-describing formats are not
|
||||
/// able to deserialize something like `serde_json::Value` which relies on
|
||||
@@ -877,7 +884,7 @@ where
|
||||
/// `Deserializer::deserialize_any` unless you need to be told by the
|
||||
/// Deserializer what type is in the input. Know that relying on
|
||||
/// `Deserializer::deserialize_any` means your data type will be able to
|
||||
/// deserialize from self-describing formats only, ruling out Bincode and many
|
||||
/// deserialize from self-describing formats only, ruling out Postcard and many
|
||||
/// others.
|
||||
///
|
||||
/// [Serde data model]: https://serde.rs/data-model.html
|
||||
@@ -908,7 +915,7 @@ pub trait Deserializer<'de>: Sized {
|
||||
/// `Deserializer::deserialize_any` unless you need to be told by the
|
||||
/// Deserializer what type is in the input. Know that relying on
|
||||
/// `Deserializer::deserialize_any` means your data type will be able to
|
||||
/// deserialize from self-describing formats only, ruling out Bincode and
|
||||
/// deserialize from self-describing formats only, ruling out Postcard and
|
||||
/// many others.
|
||||
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
@@ -1149,10 +1156,10 @@ pub trait Deserializer<'de>: Sized {
|
||||
/// Some types have a human-readable form that may be somewhat expensive to
|
||||
/// construct, as well as a binary form that is compact and efficient.
|
||||
/// Generally text-based formats like JSON and YAML will prefer to use the
|
||||
/// human-readable one and binary formats like Bincode will prefer the
|
||||
/// human-readable one and binary formats like Postcard will prefer the
|
||||
/// compact one.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::ops::Add;
|
||||
/// # use std::str::FromStr;
|
||||
/// #
|
||||
@@ -1213,6 +1220,20 @@ pub trait Deserializer<'de>: Sized {
|
||||
fn is_human_readable(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
// Not public API.
|
||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
||||
#[doc(hidden)]
|
||||
fn __deserialize_content<V>(
|
||||
self,
|
||||
_: ::actually_private::T,
|
||||
visitor: V,
|
||||
) -> Result<::private::de::Content<'de>, Self::Error>
|
||||
where
|
||||
V: Visitor<'de, Value = ::private::de::Content<'de>>,
|
||||
{
|
||||
self.deserialize_any(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1229,10 +1250,9 @@ pub trait Deserializer<'de>: Sized {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use std::fmt;
|
||||
/// #
|
||||
/// ```edition2021
|
||||
/// # use serde::de::{self, Unexpected, Visitor};
|
||||
/// # use std::fmt;
|
||||
/// #
|
||||
/// /// A visitor that deserializes a long string - a string containing at least
|
||||
/// /// some minimum number of bytes.
|
||||
@@ -1270,7 +1290,7 @@ pub trait Visitor<'de>: Sized {
|
||||
/// "an integer between 0 and 64". The message should not be capitalized and
|
||||
/// should not end with a period.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::fmt;
|
||||
/// #
|
||||
/// # struct S {
|
||||
@@ -1352,8 +1372,10 @@ pub trait Visitor<'de>: Sized {
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let _ = v;
|
||||
Err(Error::invalid_type(Unexpected::Other("i128"), &self))
|
||||
let mut buf = [0u8; 58];
|
||||
let mut writer = format::Buf::new(&mut buf);
|
||||
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as i128", v)).unwrap();
|
||||
Err(Error::invalid_type(Unexpected::Other(writer.as_str()), &self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1412,8 +1434,10 @@ pub trait Visitor<'de>: Sized {
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let _ = v;
|
||||
Err(Error::invalid_type(Unexpected::Other("u128"), &self))
|
||||
let mut buf = [0u8; 57];
|
||||
let mut writer = format::Buf::new(&mut buf);
|
||||
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as u128", v)).unwrap();
|
||||
Err(Error::invalid_type(Unexpected::Other(writer.as_str()), &self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1535,7 +1559,7 @@ pub trait Visitor<'de>: Sized {
|
||||
/// `Deserializer`.
|
||||
///
|
||||
/// This enables zero-copy deserialization of bytes in some formats. For
|
||||
/// example Bincode data containing bytes can be deserialized with zero
|
||||
/// example Postcard data containing bytes can be deserialized with zero
|
||||
/// copying into a `&'a [u8]` as long as the input data outlives `'a`.
|
||||
///
|
||||
/// The default implementation forwards to `visit_bytes`.
|
||||
@@ -2011,7 +2035,7 @@ pub trait VariantAccess<'de>: Sized {
|
||||
/// If the data contains a different type of variant, the following
|
||||
/// `invalid_type` error should be constructed:
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||
/// #
|
||||
/// # struct X;
|
||||
@@ -2051,7 +2075,7 @@ pub trait VariantAccess<'de>: Sized {
|
||||
/// If the data contains a different type of variant, the following
|
||||
/// `invalid_type` error should be constructed:
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||
/// #
|
||||
/// # struct X;
|
||||
@@ -2107,7 +2131,7 @@ pub trait VariantAccess<'de>: Sized {
|
||||
/// If the data contains a different type of variant, the following
|
||||
/// `invalid_type` error should be constructed:
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||
/// #
|
||||
/// # struct X;
|
||||
@@ -2124,11 +2148,7 @@ pub trait VariantAccess<'de>: Sized {
|
||||
/// # T: DeserializeSeed<'de>,
|
||||
/// # { unimplemented!() }
|
||||
/// #
|
||||
/// fn tuple_variant<V>(
|
||||
/// self,
|
||||
/// _len: usize,
|
||||
/// _visitor: V,
|
||||
/// ) -> Result<V::Value, Self::Error>
|
||||
/// fn tuple_variant<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error>
|
||||
/// where
|
||||
/// V: Visitor<'de>,
|
||||
/// {
|
||||
@@ -2154,7 +2174,7 @@ pub trait VariantAccess<'de>: Sized {
|
||||
/// If the data contains a different type of variant, the following
|
||||
/// `invalid_type` error should be constructed:
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||
/// #
|
||||
/// # struct X;
|
||||
@@ -2214,10 +2234,10 @@ pub trait VariantAccess<'de>: Sized {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::de::{value, Deserialize, IntoDeserializer};
|
||||
/// use serde_derive::Deserialize;
|
||||
/// use std::str::FromStr;
|
||||
/// use serde::Deserialize;
|
||||
/// use serde::de::{value, IntoDeserializer};
|
||||
///
|
||||
/// #[derive(Deserialize)]
|
||||
/// enum Setting {
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn encode(c: char) -> Encode {
|
||||
buf[3] = (code & 0x3F) as u8 | TAG_CONT;
|
||||
0
|
||||
};
|
||||
Encode { buf: buf, pos: pos }
|
||||
Encode { buf, pos }
|
||||
}
|
||||
|
||||
pub struct Encode {
|
||||
|
||||
+100
-25
@@ -1,10 +1,10 @@
|
||||
//! Building blocks for deserializing basic values using the `IntoDeserializer`
|
||||
//! trait.
|
||||
//!
|
||||
//! ```edition2018
|
||||
//! ```edition2021
|
||||
//! use serde::de::{value, Deserialize, IntoDeserializer};
|
||||
//! use serde_derive::Deserialize;
|
||||
//! use std::str::FromStr;
|
||||
//! use serde::Deserialize;
|
||||
//! use serde::de::{value, IntoDeserializer};
|
||||
//!
|
||||
//! #[derive(Deserialize)]
|
||||
//! enum Setting {
|
||||
@@ -128,9 +128,7 @@ where
|
||||
type Deserializer = UnitDeserializer<E>;
|
||||
|
||||
fn into_deserializer(self) -> UnitDeserializer<E> {
|
||||
UnitDeserializer {
|
||||
marker: PhantomData,
|
||||
}
|
||||
UnitDeserializer::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +139,15 @@ pub struct UnitDeserializer<E> {
|
||||
|
||||
impl_copy_clone!(UnitDeserializer);
|
||||
|
||||
impl<E> UnitDeserializer<E> {
|
||||
#[allow(missing_docs)]
|
||||
pub fn new() -> Self {
|
||||
UnitDeserializer {
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, E> de::Deserializer<'de> for UnitDeserializer<E>
|
||||
where
|
||||
E: de::Error,
|
||||
@@ -236,8 +243,15 @@ macro_rules! primitive_deserializer {
|
||||
type Deserializer = $name<E>;
|
||||
|
||||
fn into_deserializer(self) -> $name<E> {
|
||||
$name::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> $name<E> {
|
||||
#[allow(missing_docs)]
|
||||
pub fn new(value: $ty) -> Self {
|
||||
$name {
|
||||
value: self,
|
||||
value,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -308,8 +322,15 @@ where
|
||||
type Deserializer = U32Deserializer<E>;
|
||||
|
||||
fn into_deserializer(self) -> U32Deserializer<E> {
|
||||
U32Deserializer::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> U32Deserializer<E> {
|
||||
#[allow(missing_docs)]
|
||||
pub fn new(value: u32) -> Self {
|
||||
U32Deserializer {
|
||||
value: self,
|
||||
value,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -390,8 +411,15 @@ where
|
||||
type Deserializer = StrDeserializer<'a, E>;
|
||||
|
||||
fn into_deserializer(self) -> StrDeserializer<'a, E> {
|
||||
StrDeserializer::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E> StrDeserializer<'a, E> {
|
||||
#[allow(missing_docs)]
|
||||
pub fn new(value: &'a str) -> Self {
|
||||
StrDeserializer {
|
||||
value: self,
|
||||
value,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -470,7 +498,7 @@ impl<'de, E> BorrowedStrDeserializer<'de, E> {
|
||||
/// Create a new borrowed deserializer from the given string.
|
||||
pub fn new(value: &'de str) -> BorrowedStrDeserializer<'de, E> {
|
||||
BorrowedStrDeserializer {
|
||||
value: value,
|
||||
value,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -561,8 +589,16 @@ where
|
||||
type Deserializer = StringDeserializer<E>;
|
||||
|
||||
fn into_deserializer(self) -> StringDeserializer<E> {
|
||||
StringDeserializer::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<E> StringDeserializer<E> {
|
||||
#[allow(missing_docs)]
|
||||
pub fn new(value: String) -> Self {
|
||||
StringDeserializer {
|
||||
value: self,
|
||||
value,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -604,7 +640,7 @@ where
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<'de, 'a, E> de::EnumAccess<'de> for StringDeserializer<E>
|
||||
impl<'de, E> de::EnumAccess<'de> for StringDeserializer<E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
@@ -656,8 +692,16 @@ where
|
||||
type Deserializer = CowStrDeserializer<'a, E>;
|
||||
|
||||
fn into_deserializer(self) -> CowStrDeserializer<'a, E> {
|
||||
CowStrDeserializer::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<'a, E> CowStrDeserializer<'a, E> {
|
||||
#[allow(missing_docs)]
|
||||
pub fn new(value: Cow<'a, str>) -> Self {
|
||||
CowStrDeserializer {
|
||||
value: self,
|
||||
value,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -739,7 +783,7 @@ impl<'a, E> BytesDeserializer<'a, E> {
|
||||
/// Create a new deserializer from the given bytes.
|
||||
pub fn new(value: &'a [u8]) -> Self {
|
||||
BytesDeserializer {
|
||||
value: value,
|
||||
value,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -798,7 +842,7 @@ impl<'de, E> BorrowedBytesDeserializer<'de, E> {
|
||||
/// Create a new borrowed deserializer from the given borrowed bytes.
|
||||
pub fn new(value: &'de [u8]) -> Self {
|
||||
BorrowedBytesDeserializer {
|
||||
value: value,
|
||||
value,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -1009,7 +1053,7 @@ pub struct SeqAccessDeserializer<A> {
|
||||
impl<A> SeqAccessDeserializer<A> {
|
||||
/// Construct a new `SeqAccessDeserializer<A>`.
|
||||
pub fn new(seq: A) -> Self {
|
||||
SeqAccessDeserializer { seq: seq }
|
||||
SeqAccessDeserializer { seq }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1410,7 +1454,7 @@ pub struct MapAccessDeserializer<A> {
|
||||
impl<A> MapAccessDeserializer<A> {
|
||||
/// Construct a new `MapAccessDeserializer<A>`.
|
||||
pub fn new(map: A) -> Self {
|
||||
MapAccessDeserializer { map: map }
|
||||
MapAccessDeserializer { map }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1457,7 +1501,7 @@ where
|
||||
where
|
||||
T: de::DeserializeSeed<'de>,
|
||||
{
|
||||
match self.map.next_key_seed(seed)? {
|
||||
match try!(self.map.next_key_seed(seed)) {
|
||||
Some(key) => Ok((key, private::map_as_enum(self.map))),
|
||||
None => Err(de::Error::invalid_type(de::Unexpected::Map, &"enum")),
|
||||
}
|
||||
@@ -1466,6 +1510,41 @@ where
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// A deserializer holding an `EnumAccess`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct EnumAccessDeserializer<A> {
|
||||
access: A,
|
||||
}
|
||||
|
||||
impl<A> EnumAccessDeserializer<A> {
|
||||
/// Construct a new `EnumAccessDeserializer<A>`.
|
||||
pub fn new(access: A) -> Self {
|
||||
EnumAccessDeserializer { access }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, A> de::Deserializer<'de> for EnumAccessDeserializer<A>
|
||||
where
|
||||
A: de::EnumAccess<'de>,
|
||||
{
|
||||
type Error = A::Error;
|
||||
|
||||
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
V: de::Visitor<'de>,
|
||||
{
|
||||
visitor.visit_enum(self.access)
|
||||
}
|
||||
|
||||
forward_to_deserialize_any! {
|
||||
bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
|
||||
bytes byte_buf option unit unit_struct newtype_struct seq tuple
|
||||
tuple_struct map struct enum identifier ignored_any
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mod private {
|
||||
use lib::*;
|
||||
|
||||
@@ -1534,7 +1613,7 @@ mod private {
|
||||
}
|
||||
|
||||
pub fn map_as_enum<A>(map: A) -> MapAsEnum<A> {
|
||||
MapAsEnum { map: map }
|
||||
MapAsEnum { map }
|
||||
}
|
||||
|
||||
impl<'de, A> VariantAccess<'de> for MapAsEnum<A>
|
||||
@@ -1558,10 +1637,7 @@ mod private {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
self.map.next_value_seed(SeedTupleVariant {
|
||||
len: len,
|
||||
visitor: visitor,
|
||||
})
|
||||
self.map.next_value_seed(SeedTupleVariant { len, visitor })
|
||||
}
|
||||
|
||||
fn struct_variant<V>(
|
||||
@@ -1572,8 +1648,7 @@ mod private {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
self.map
|
||||
.next_value_seed(SeedStructVariant { visitor: visitor })
|
||||
self.map.next_value_seed(SeedStructVariant { visitor })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
/// or do not target platforms that lack 128-bit integers, do not need to
|
||||
/// bother with this macro and may assume support for 128-bit integers.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::__private::doc::Error;
|
||||
/// #
|
||||
/// # struct MySerializer;
|
||||
@@ -50,7 +50,7 @@
|
||||
/// When Serde is built with support for 128-bit integers, this macro expands
|
||||
/// transparently into just the input tokens.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// macro_rules! serde_if_integer128 {
|
||||
/// ($($tt:tt)*) => {
|
||||
/// $($tt)*
|
||||
@@ -61,12 +61,12 @@
|
||||
/// When built without support for 128-bit integers, this macro expands to
|
||||
/// nothing.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// macro_rules! serde_if_integer128 {
|
||||
/// ($($tt:tt)*) => {};
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg(integer128)]
|
||||
#[cfg(not(no_integer128))]
|
||||
#[macro_export]
|
||||
macro_rules! serde_if_integer128 {
|
||||
($($tt:tt)*) => {
|
||||
@@ -74,7 +74,7 @@ macro_rules! serde_if_integer128 {
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(not(integer128))]
|
||||
#[cfg(no_integer128)]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! serde_if_integer128 {
|
||||
|
||||
+84
-31
@@ -31,8 +31,7 @@
|
||||
//! for Serde by the community.
|
||||
//!
|
||||
//! - [JSON], the ubiquitous JavaScript Object Notation used by many HTTP APIs.
|
||||
//! - [Bincode], a compact binary format
|
||||
//! used for IPC within the Servo rendering engine.
|
||||
//! - [Postcard], a no\_std and embedded-systems friendly compact binary format.
|
||||
//! - [CBOR], a Concise Binary Object Representation designed for small message
|
||||
//! size without the need for version negotiation.
|
||||
//! - [YAML], a self-proclaimed human-friendly configuration language that ain't
|
||||
@@ -45,8 +44,9 @@
|
||||
//! - [Avro], a binary format used within Apache Hadoop, with support for schema
|
||||
//! definition.
|
||||
//! - [JSON5], a superset of JSON including some productions from ES5.
|
||||
//! - [Postcard], a no\_std and embedded-systems friendly compact binary format.
|
||||
//! - [URL] query strings, in the x-www-form-urlencoded format.
|
||||
//! - [Starlark], the format used for describing build targets by the Bazel and
|
||||
//! Buck build systems. *(serialization only)*
|
||||
//! - [Envy], a way to deserialize environment variables into Rust structs.
|
||||
//! *(deserialization only)*
|
||||
//! - [Envy Store], a way to deserialize [AWS Parameter Store] parameters into
|
||||
@@ -54,58 +54,66 @@
|
||||
//! - [S-expressions], the textual representation of code and data used by the
|
||||
//! Lisp language family.
|
||||
//! - [D-Bus]'s binary wire format.
|
||||
//! - [FlexBuffers], the schemaless cousin of Google's FlatBuffers zero-copy serialization format.
|
||||
//! - [FlexBuffers], the schemaless cousin of Google's FlatBuffers zero-copy
|
||||
//! serialization format.
|
||||
//! - [Bencode], a simple binary format used in the BitTorrent protocol.
|
||||
//! - [Token streams], for processing Rust procedural macro input.
|
||||
//! *(deserialization only)*
|
||||
//! - [DynamoDB Items], the format used by [rusoto_dynamodb] to transfer data to
|
||||
//! and from DynamoDB.
|
||||
//! - [Hjson], a syntax extension to JSON designed around human reading and
|
||||
//! editing. *(deserialization only)*
|
||||
//!
|
||||
//! [JSON]: https://github.com/serde-rs/json
|
||||
//! [Bincode]: https://github.com/servo/bincode
|
||||
//! [CBOR]: https://github.com/pyfisch/cbor
|
||||
//! [Postcard]: https://github.com/jamesmunns/postcard
|
||||
//! [CBOR]: https://github.com/enarx/ciborium
|
||||
//! [YAML]: https://github.com/dtolnay/serde-yaml
|
||||
//! [MessagePack]: https://github.com/3Hren/msgpack-rust
|
||||
//! [TOML]: https://github.com/alexcrichton/toml-rs
|
||||
//! [TOML]: https://docs.rs/toml
|
||||
//! [Pickle]: https://github.com/birkenfeld/serde-pickle
|
||||
//! [RON]: https://github.com/ron-rs/ron
|
||||
//! [BSON]: https://github.com/zonyitoo/bson-rs
|
||||
//! [Avro]: https://github.com/flavray/avro-rs
|
||||
//! [BSON]: https://github.com/mongodb/bson-rust
|
||||
//! [Avro]: https://docs.rs/apache-avro
|
||||
//! [JSON5]: https://github.com/callum-oakley/json5-rs
|
||||
//! [Postcard]: https://github.com/jamesmunns/postcard
|
||||
//! [URL]: https://docs.rs/serde_qs
|
||||
//! [Starlark]: https://github.com/dtolnay/serde-starlark
|
||||
//! [Envy]: https://github.com/softprops/envy
|
||||
//! [Envy Store]: https://github.com/softprops/envy-store
|
||||
//! [Cargo]: http://doc.crates.io/manifest.html
|
||||
//! [AWS Parameter Store]: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html
|
||||
//! [Cargo]: https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
//! [AWS Parameter Store]: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html
|
||||
//! [S-expressions]: https://github.com/rotty/lexpr-rs
|
||||
//! [D-Bus]: https://docs.rs/zvariant
|
||||
//! [FlexBuffers]: https://github.com/google/flatbuffers/tree/master/rust/flexbuffers
|
||||
//! [Bencode]: https://github.com/P3KI/bendy
|
||||
//! [Token streams]: https://github.com/oxidecomputer/serde_tokenstream
|
||||
//! [DynamoDB Items]: https://docs.rs/serde_dynamo
|
||||
//! [rusoto_dynamodb]: https://docs.rs/rusoto_dynamodb
|
||||
//! [Hjson]: https://github.com/Canop/deser-hjson
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Serde types in rustdoc of other crates get linked to here.
|
||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.130")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.172")]
|
||||
// Support using Serde without the standard library!
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
// Unstable functionality only if the user asks for it. For tracking and
|
||||
// discussion of these features please refer to this issue:
|
||||
//
|
||||
// https://github.com/serde-rs/serde/issues/812
|
||||
#![cfg_attr(feature = "unstable", feature(never_type))]
|
||||
#![cfg_attr(feature = "unstable", feature(error_in_core, never_type))]
|
||||
#![allow(unknown_lints, bare_trait_objects, deprecated)]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||
// Ignored clippy and clippy_pedantic lints
|
||||
#![cfg_attr(
|
||||
feature = "cargo-clippy",
|
||||
allow(
|
||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704
|
||||
unnested_or_patterns,
|
||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/7768
|
||||
semicolon_if_nothing_returned,
|
||||
// not available in our oldest supported compiler
|
||||
checked_conversions,
|
||||
empty_enum,
|
||||
redundant_field_names,
|
||||
redundant_static_lifetimes,
|
||||
type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
|
||||
// integer and float ser/de requires these sorts of casts
|
||||
cast_possible_truncation,
|
||||
cast_possible_wrap,
|
||||
@@ -119,9 +127,12 @@
|
||||
use_self,
|
||||
zero_prefixed_literal,
|
||||
// correctly used
|
||||
derive_partial_eq_without_eq,
|
||||
enum_glob_use,
|
||||
let_underscore_drop,
|
||||
explicit_auto_deref,
|
||||
let_underscore_untyped,
|
||||
map_err_ignore,
|
||||
new_without_default,
|
||||
result_unit_err,
|
||||
wildcard_imports,
|
||||
// not practical
|
||||
@@ -169,7 +180,7 @@ mod lib {
|
||||
pub use self::core::fmt::{self, Debug, Display};
|
||||
pub use self::core::marker::{self, PhantomData};
|
||||
pub use self::core::num::Wrapping;
|
||||
pub use self::core::ops::Range;
|
||||
pub use self::core::ops::{Range, RangeFrom, RangeTo};
|
||||
pub use self::core::option::{self, Option};
|
||||
pub use self::core::result::{self, Result};
|
||||
|
||||
@@ -208,13 +219,23 @@ mod lib {
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
||||
|
||||
#[cfg(all(not(no_core_cstr), not(feature = "std")))]
|
||||
pub use core::ffi::CStr;
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::ffi::CStr;
|
||||
|
||||
#[cfg(all(not(no_core_cstr), feature = "alloc", not(feature = "std")))]
|
||||
pub use alloc::ffi::CString;
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::ffi::CString;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::{error, net};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::collections::{HashMap, HashSet};
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::ffi::{CStr, CString, OsStr, OsString};
|
||||
pub use std::ffi::{OsStr, OsString};
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::hash::{BuildHasher, Hash};
|
||||
#[cfg(feature = "std")]
|
||||
@@ -226,30 +247,56 @@ mod lib {
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[cfg(all(feature = "std", collections_bound))]
|
||||
#[cfg(all(feature = "std", not(no_collections_bound), no_ops_bound))]
|
||||
pub use std::collections::Bound;
|
||||
|
||||
#[cfg(core_reverse)]
|
||||
#[cfg(not(no_core_reverse))]
|
||||
pub use self::core::cmp::Reverse;
|
||||
|
||||
#[cfg(ops_bound)]
|
||||
#[cfg(not(no_ops_bound))]
|
||||
pub use self::core::ops::Bound;
|
||||
|
||||
#[cfg(range_inclusive)]
|
||||
#[cfg(not(no_range_inclusive))]
|
||||
pub use self::core::ops::RangeInclusive;
|
||||
|
||||
#[cfg(all(feature = "std", std_atomic))]
|
||||
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
|
||||
pub use std::sync::atomic::{
|
||||
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
|
||||
AtomicUsize, Ordering,
|
||||
};
|
||||
#[cfg(all(feature = "std", std_atomic64))]
|
||||
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
|
||||
pub use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||
|
||||
#[cfg(any(core_duration, feature = "std"))]
|
||||
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
|
||||
pub use std::sync::atomic::Ordering;
|
||||
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "8"))]
|
||||
pub use std::sync::atomic::{AtomicBool, AtomicI8, AtomicU8};
|
||||
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "16"))]
|
||||
pub use std::sync::atomic::{AtomicI16, AtomicU16};
|
||||
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "32"))]
|
||||
pub use std::sync::atomic::{AtomicI32, AtomicU32};
|
||||
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "64"))]
|
||||
pub use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]
|
||||
pub use std::sync::atomic::{AtomicIsize, AtomicUsize};
|
||||
|
||||
#[cfg(any(feature = "std", not(no_core_duration)))]
|
||||
pub use self::core::time::Duration;
|
||||
}
|
||||
|
||||
// None of this crate's error handling needs the `From::from` error conversion
|
||||
// performed implicitly by the `?` operator or the standard library's `try!`
|
||||
// macro. This simplified macro gives a 5.5% improvement in compile time
|
||||
// compared to standard `try!`, and 9% improvement compared to `?`.
|
||||
macro_rules! try {
|
||||
($expr:expr) => {
|
||||
match $expr {
|
||||
Ok(val) => val,
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[macro_use]
|
||||
@@ -279,7 +326,7 @@ use self::__private as private;
|
||||
#[path = "de/seed.rs"]
|
||||
mod seed;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
||||
mod std_error;
|
||||
|
||||
// Re-export #[derive(Serialize, Deserialize)].
|
||||
@@ -291,6 +338,12 @@ mod std_error;
|
||||
#[allow(unused_imports)]
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
/// Derive macro available if serde is built with `features = ["derive"]`.
|
||||
#[cfg(feature = "serde_derive")]
|
||||
#[doc(hidden)]
|
||||
pub use serde_derive::*;
|
||||
pub use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
|
||||
mod actually_private {
|
||||
pub struct T;
|
||||
}
|
||||
|
||||
+4
-5
@@ -11,7 +11,7 @@
|
||||
/// input. This requires repetitive implementations of all the [`Deserializer`]
|
||||
/// trait methods.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::forward_to_deserialize_any;
|
||||
/// # use serde::de::{value, Deserializer, Visitor};
|
||||
/// #
|
||||
@@ -47,7 +47,7 @@
|
||||
/// methods so that they forward directly to [`Deserializer::deserialize_any`].
|
||||
/// You can choose which methods to forward.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::forward_to_deserialize_any;
|
||||
/// # use serde::de::{value, Deserializer, Visitor};
|
||||
/// #
|
||||
@@ -78,11 +78,10 @@
|
||||
/// called `V`. A different type parameter and a different lifetime can be
|
||||
/// specified explicitly if necessary.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use std::marker::PhantomData;
|
||||
/// #
|
||||
/// ```edition2021
|
||||
/// # use serde::forward_to_deserialize_any;
|
||||
/// # use serde::de::{value, Deserializer, Visitor};
|
||||
/// # use std::marker::PhantomData;
|
||||
/// #
|
||||
/// # struct MyDeserializer<V>(PhantomData<V>);
|
||||
/// #
|
||||
|
||||
+177
-160
@@ -206,6 +206,7 @@ mod content {
|
||||
use lib::*;
|
||||
|
||||
use __private::size_hint;
|
||||
use actually_private;
|
||||
use de::{
|
||||
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
|
||||
MapAccess, SeqAccess, Unexpected, Visitor,
|
||||
@@ -215,7 +216,7 @@ mod content {
|
||||
/// deserializing untagged enums and internally tagged enums.
|
||||
///
|
||||
/// Not public API. Use serde-value instead.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Content<'de> {
|
||||
Bool(bool),
|
||||
|
||||
@@ -294,7 +295,7 @@ mod content {
|
||||
// Untagged and internally tagged enums are only supported in
|
||||
// self-describing formats.
|
||||
let visitor = ContentVisitor { value: PhantomData };
|
||||
deserializer.deserialize_any(visitor)
|
||||
deserializer.__deserialize_content(actually_private::T, visitor)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,7 +474,8 @@ mod content {
|
||||
where
|
||||
V: SeqAccess<'de>,
|
||||
{
|
||||
let mut vec = Vec::with_capacity(size_hint::cautious(visitor.size_hint()));
|
||||
let mut vec =
|
||||
Vec::<Content>::with_capacity(size_hint::cautious::<Content>(visitor.size_hint()));
|
||||
while let Some(e) = try!(visitor.next_element()) {
|
||||
vec.push(e);
|
||||
}
|
||||
@@ -484,7 +486,10 @@ mod content {
|
||||
where
|
||||
V: MapAccess<'de>,
|
||||
{
|
||||
let mut vec = Vec::with_capacity(size_hint::cautious(visitor.size_hint()));
|
||||
let mut vec =
|
||||
Vec::<(Content, Content)>::with_capacity(
|
||||
size_hint::cautious::<(Content, Content)>(visitor.size_hint()),
|
||||
);
|
||||
while let Some(kv) = try!(visitor.next_entry()) {
|
||||
vec.push(kv);
|
||||
}
|
||||
@@ -517,7 +522,7 @@ mod content {
|
||||
impl<'de> TagOrContentVisitor<'de> {
|
||||
fn new(name: &'static str) -> Self {
|
||||
TagOrContentVisitor {
|
||||
name: name,
|
||||
name,
|
||||
value: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -796,51 +801,29 @@ mod content {
|
||||
/// Used by generated code to deserialize an internally tagged enum.
|
||||
///
|
||||
/// Not public API.
|
||||
pub struct TaggedContent<'de, T> {
|
||||
pub tag: T,
|
||||
pub content: Content<'de>,
|
||||
}
|
||||
|
||||
/// Not public API.
|
||||
pub struct TaggedContentVisitor<'de, T> {
|
||||
pub struct TaggedContentVisitor<T> {
|
||||
tag_name: &'static str,
|
||||
expecting: &'static str,
|
||||
value: PhantomData<TaggedContent<'de, T>>,
|
||||
value: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<'de, T> TaggedContentVisitor<'de, T> {
|
||||
impl<T> TaggedContentVisitor<T> {
|
||||
/// Visitor for the content of an internally tagged enum with the given
|
||||
/// tag name.
|
||||
pub fn new(name: &'static str, expecting: &'static str) -> Self {
|
||||
TaggedContentVisitor {
|
||||
tag_name: name,
|
||||
expecting: expecting,
|
||||
expecting,
|
||||
value: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T> DeserializeSeed<'de> for TaggedContentVisitor<'de, T>
|
||||
impl<'de, T> Visitor<'de> for TaggedContentVisitor<T>
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
type Value = TaggedContent<'de, T>;
|
||||
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
// Internally tagged enums are only supported in self-describing
|
||||
// formats.
|
||||
deserializer.deserialize_any(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T> Visitor<'de> for TaggedContentVisitor<'de, T>
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
type Value = TaggedContent<'de, T>;
|
||||
type Value = (T, Content<'de>);
|
||||
|
||||
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.write_str(self.expecting)
|
||||
@@ -857,10 +840,7 @@ mod content {
|
||||
}
|
||||
};
|
||||
let rest = de::value::SeqAccessDeserializer::new(seq);
|
||||
Ok(TaggedContent {
|
||||
tag: tag,
|
||||
content: try!(Content::deserialize(rest)),
|
||||
})
|
||||
Ok((tag, try!(Content::deserialize(rest))))
|
||||
}
|
||||
|
||||
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
|
||||
@@ -868,7 +848,10 @@ mod content {
|
||||
M: MapAccess<'de>,
|
||||
{
|
||||
let mut tag = None;
|
||||
let mut vec = Vec::with_capacity(size_hint::cautious(map.size_hint()));
|
||||
let mut vec = Vec::<(Content, Content)>::with_capacity(size_hint::cautious::<(
|
||||
Content,
|
||||
Content,
|
||||
)>(map.size_hint()));
|
||||
while let Some(k) = try!(map.next_key_seed(TagOrContentVisitor::new(self.tag_name))) {
|
||||
match k {
|
||||
TagOrContent::Tag => {
|
||||
@@ -885,10 +868,7 @@ mod content {
|
||||
}
|
||||
match tag {
|
||||
None => Err(de::Error::missing_field(self.tag_name)),
|
||||
Some(tag) => Ok(TaggedContent {
|
||||
tag: tag,
|
||||
content: Content::Map(vec),
|
||||
}),
|
||||
Some(tag) => Ok((tag, Content::Map(vec))),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -914,7 +894,7 @@ mod content {
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(self)
|
||||
deserializer.deserialize_identifier(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -925,6 +905,20 @@ mod content {
|
||||
write!(formatter, "{:?} or {:?}", self.tag, self.content)
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, field_index: u64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
match field_index {
|
||||
0 => Ok(TagOrContentField::Tag),
|
||||
1 => Ok(TagOrContentField::Content),
|
||||
_ => Err(de::Error::invalid_value(
|
||||
Unexpected::Unsigned(field_index),
|
||||
&self,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, field: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
@@ -937,6 +931,19 @@ mod content {
|
||||
Err(de::Error::invalid_value(Unexpected::Str(field), &self))
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_bytes<E>(self, field: &[u8]) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if field == self.tag.as_bytes() {
|
||||
Ok(TagOrContentField::Tag)
|
||||
} else if field == self.content.as_bytes() {
|
||||
Ok(TagOrContentField::Content)
|
||||
} else {
|
||||
Err(de::Error::invalid_value(Unexpected::Bytes(field), &self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Used by generated code to deserialize an adjacently tagged enum when
|
||||
@@ -962,7 +969,7 @@ mod content {
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(self)
|
||||
deserializer.deserialize_identifier(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -977,13 +984,31 @@ mod content {
|
||||
)
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, field_index: u64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
match field_index {
|
||||
0 => Ok(TagContentOtherField::Tag),
|
||||
1 => Ok(TagContentOtherField::Content),
|
||||
_ => Ok(TagContentOtherField::Other),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, field: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if field == self.tag {
|
||||
self.visit_bytes(field.as_bytes())
|
||||
}
|
||||
|
||||
fn visit_bytes<E>(self, field: &[u8]) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if field == self.tag.as_bytes() {
|
||||
Ok(TagContentOtherField::Tag)
|
||||
} else if field == self.content {
|
||||
} else if field == self.content.as_bytes() {
|
||||
Ok(TagContentOtherField::Content)
|
||||
} else {
|
||||
Ok(TagContentOtherField::Other)
|
||||
@@ -1261,6 +1286,17 @@ mod content {
|
||||
{
|
||||
match self.content {
|
||||
Content::Unit => visitor.visit_unit(),
|
||||
|
||||
// Allow deserializing newtype variant containing unit.
|
||||
//
|
||||
// #[derive(Deserialize)]
|
||||
// #[serde(tag = "result")]
|
||||
// enum Response<T> {
|
||||
// Success(T),
|
||||
// }
|
||||
//
|
||||
// We want {"result":"Success"} to deserialize into Response<()>.
|
||||
Content::Map(ref v) if v.is_empty() => visitor.visit_unit(),
|
||||
_ => Err(self.invalid_type(&visitor)),
|
||||
}
|
||||
}
|
||||
@@ -1427,13 +1463,25 @@ mod content {
|
||||
drop(self);
|
||||
visitor.visit_unit()
|
||||
}
|
||||
|
||||
fn __deserialize_content<V>(
|
||||
self,
|
||||
_: actually_private::T,
|
||||
visitor: V,
|
||||
) -> Result<Content<'de>, Self::Error>
|
||||
where
|
||||
V: Visitor<'de, Value = Content<'de>>,
|
||||
{
|
||||
let _ = visitor;
|
||||
Ok(self.content)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, E> ContentDeserializer<'de, E> {
|
||||
/// private API, don't use
|
||||
pub fn new(content: Content<'de>) -> Self {
|
||||
ContentDeserializer {
|
||||
content: content,
|
||||
content,
|
||||
err: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -1454,8 +1502,8 @@ mod content {
|
||||
{
|
||||
pub fn new(variant: Content<'de>, value: Option<Content<'de>>) -> EnumDeserializer<'de, E> {
|
||||
EnumDeserializer {
|
||||
variant: variant,
|
||||
value: value,
|
||||
variant,
|
||||
value,
|
||||
err: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -1786,7 +1834,7 @@ mod content {
|
||||
V: Visitor<'de>,
|
||||
E: de::Error,
|
||||
{
|
||||
let map = content.iter().map(|&(ref k, ref v)| {
|
||||
let map = content.iter().map(|(k, v)| {
|
||||
(
|
||||
ContentRefDeserializer::new(k),
|
||||
ContentRefDeserializer::new(v),
|
||||
@@ -2083,7 +2131,7 @@ mod content {
|
||||
let (variant, value) = match *self.content {
|
||||
Content::Map(ref value) => {
|
||||
let mut iter = value.iter();
|
||||
let &(ref variant, ref value) = match iter.next() {
|
||||
let (variant, value) = match iter.next() {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
return Err(de::Error::invalid_value(
|
||||
@@ -2111,8 +2159,8 @@ mod content {
|
||||
};
|
||||
|
||||
visitor.visit_enum(EnumRefDeserializer {
|
||||
variant: variant,
|
||||
value: value,
|
||||
variant,
|
||||
value,
|
||||
err: PhantomData,
|
||||
})
|
||||
}
|
||||
@@ -2138,18 +2186,38 @@ mod content {
|
||||
{
|
||||
visitor.visit_unit()
|
||||
}
|
||||
|
||||
fn __deserialize_content<V>(
|
||||
self,
|
||||
_: actually_private::T,
|
||||
visitor: V,
|
||||
) -> Result<Content<'de>, Self::Error>
|
||||
where
|
||||
V: Visitor<'de, Value = Content<'de>>,
|
||||
{
|
||||
let _ = visitor;
|
||||
Ok(self.content.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'de, E> ContentRefDeserializer<'a, 'de, E> {
|
||||
/// private API, don't use
|
||||
pub fn new(content: &'a Content<'de>) -> Self {
|
||||
ContentRefDeserializer {
|
||||
content: content,
|
||||
content,
|
||||
err: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'de: 'a, E> Copy for ContentRefDeserializer<'a, 'de, E> {}
|
||||
|
||||
impl<'a, 'de: 'a, E> Clone for ContentRefDeserializer<'a, 'de, E> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
struct EnumRefDeserializer<'a, 'de: 'a, E>
|
||||
where
|
||||
E: de::Error,
|
||||
@@ -2218,7 +2286,7 @@ mod content {
|
||||
V: de::Visitor<'de>,
|
||||
{
|
||||
match self.value {
|
||||
Some(&Content::Seq(ref v)) => {
|
||||
Some(Content::Seq(v)) => {
|
||||
de::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(other) => Err(de::Error::invalid_type(
|
||||
@@ -2241,10 +2309,10 @@ mod content {
|
||||
V: de::Visitor<'de>,
|
||||
{
|
||||
match self.value {
|
||||
Some(&Content::Map(ref v)) => {
|
||||
Some(Content::Map(v)) => {
|
||||
de::Deserializer::deserialize_any(MapRefDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(&Content::Seq(ref v)) => {
|
||||
Some(Content::Seq(v)) => {
|
||||
de::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor)
|
||||
}
|
||||
Some(other) => Err(de::Error::invalid_type(
|
||||
@@ -2367,7 +2435,7 @@ mod content {
|
||||
T: de::DeserializeSeed<'de>,
|
||||
{
|
||||
match self.iter.next() {
|
||||
Some(&(ref key, ref value)) => {
|
||||
Some((key, value)) => {
|
||||
self.value = Some(value);
|
||||
seed.deserialize(ContentRefDeserializer::new(key)).map(Some)
|
||||
}
|
||||
@@ -2445,8 +2513,8 @@ mod content {
|
||||
/// Not public API.
|
||||
pub fn new(type_name: &'a str, variant_name: &'a str) -> Self {
|
||||
InternallyTaggedUnitVisitor {
|
||||
type_name: type_name,
|
||||
variant_name: variant_name,
|
||||
type_name,
|
||||
variant_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2490,8 +2558,8 @@ mod content {
|
||||
/// Not public API.
|
||||
pub fn new(type_name: &'a str, variant_name: &'a str) -> Self {
|
||||
UntaggedUnitVisitor {
|
||||
type_name: type_name,
|
||||
variant_name: variant_name,
|
||||
type_name,
|
||||
variant_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2672,7 +2740,7 @@ where
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
macro_rules! forward_to_deserialize_other {
|
||||
($($func:ident ( $($arg:ty),* ))*) => {
|
||||
($($func:ident ($($arg:ty),*))*) => {
|
||||
$(
|
||||
fn $func<V>(self, $(_: $arg,)* _visitor: V) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
@@ -2695,11 +2763,7 @@ where
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
visitor.visit_map(FlatInternallyTaggedAccess {
|
||||
iter: self.0.iter_mut(),
|
||||
pending: None,
|
||||
_marker: PhantomData,
|
||||
})
|
||||
self.deserialize_map(visitor)
|
||||
}
|
||||
|
||||
fn deserialize_enum<V>(
|
||||
@@ -2711,17 +2775,8 @@ where
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
for item in self.0.iter_mut() {
|
||||
// items in the vector are nulled out when used. So we can only use
|
||||
// an item if it's still filled in and if the field is one we care
|
||||
// about.
|
||||
let use_item = match *item {
|
||||
None => false,
|
||||
Some((ref c, _)) => c.as_str().map_or(false, |x| variants.contains(&x)),
|
||||
};
|
||||
|
||||
if use_item {
|
||||
let (key, value) = item.take().unwrap();
|
||||
for entry in self.0 {
|
||||
if let Some((key, value)) = flat_map_take_entry(entry, variants) {
|
||||
return visitor.visit_enum(EnumDeserializer::new(key, Some(value)));
|
||||
}
|
||||
}
|
||||
@@ -2736,7 +2791,11 @@ where
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
visitor.visit_map(FlatMapAccess::new(self.0.iter()))
|
||||
visitor.visit_map(FlatMapAccess {
|
||||
iter: self.0.iter(),
|
||||
pending_content: None,
|
||||
_marker: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn deserialize_struct<V>(
|
||||
@@ -2748,7 +2807,12 @@ where
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
visitor.visit_map(FlatStructAccess::new(self.0.iter_mut(), fields))
|
||||
visitor.visit_map(FlatStructAccess {
|
||||
iter: self.0.iter_mut(),
|
||||
pending_content: None,
|
||||
fields,
|
||||
_marker: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
|
||||
@@ -2775,6 +2839,13 @@ where
|
||||
visitor.visit_unit()
|
||||
}
|
||||
|
||||
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
visitor.visit_unit()
|
||||
}
|
||||
|
||||
forward_to_deserialize_other! {
|
||||
deserialize_bool()
|
||||
deserialize_i8()
|
||||
@@ -2797,30 +2868,16 @@ where
|
||||
deserialize_tuple(usize)
|
||||
deserialize_tuple_struct(&'static str, usize)
|
||||
deserialize_identifier()
|
||||
deserialize_ignored_any()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
pub struct FlatMapAccess<'a, 'de: 'a, E> {
|
||||
struct FlatMapAccess<'a, 'de: 'a, E> {
|
||||
iter: slice::Iter<'a, Option<(Content<'de>, Content<'de>)>>,
|
||||
pending_content: Option<&'a Content<'de>>,
|
||||
_marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<'a, 'de, E> FlatMapAccess<'a, 'de, E> {
|
||||
fn new(
|
||||
iter: slice::Iter<'a, Option<(Content<'de>, Content<'de>)>>,
|
||||
) -> FlatMapAccess<'a, 'de, E> {
|
||||
FlatMapAccess {
|
||||
iter: iter,
|
||||
pending_content: None,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<'a, 'de, E> MapAccess<'de> for FlatMapAccess<'a, 'de, E>
|
||||
where
|
||||
@@ -2835,6 +2892,10 @@ where
|
||||
for item in &mut self.iter {
|
||||
// Items in the vector are nulled out when used by a struct.
|
||||
if let Some((ref key, ref content)) = *item {
|
||||
// Do not take(), instead borrow this entry. The internally tagged
|
||||
// enum does its own buffering so we can't tell whether this entry
|
||||
// is going to be consumed. Borrowing here leaves the entry
|
||||
// available for later flattened fields.
|
||||
self.pending_content = Some(content);
|
||||
return seed.deserialize(ContentRefDeserializer::new(key)).map(Some);
|
||||
}
|
||||
@@ -2854,28 +2915,13 @@ where
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
pub struct FlatStructAccess<'a, 'de: 'a, E> {
|
||||
struct FlatStructAccess<'a, 'de: 'a, E> {
|
||||
iter: slice::IterMut<'a, Option<(Content<'de>, Content<'de>)>>,
|
||||
pending_content: Option<Content<'de>>,
|
||||
fields: &'static [&'static str],
|
||||
_marker: PhantomData<E>,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<'a, 'de, E> FlatStructAccess<'a, 'de, E> {
|
||||
fn new(
|
||||
iter: slice::IterMut<'a, Option<(Content<'de>, Content<'de>)>>,
|
||||
fields: &'static [&'static str],
|
||||
) -> FlatStructAccess<'a, 'de, E> {
|
||||
FlatStructAccess {
|
||||
iter: iter,
|
||||
pending_content: None,
|
||||
fields: fields,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<'a, 'de, E> MapAccess<'de> for FlatStructAccess<'a, 'de, E>
|
||||
where
|
||||
@@ -2887,17 +2933,8 @@ where
|
||||
where
|
||||
T: DeserializeSeed<'de>,
|
||||
{
|
||||
while let Some(item) = self.iter.next() {
|
||||
// items in the vector are nulled out when used. So we can only use
|
||||
// an item if it's still filled in and if the field is one we care
|
||||
// about. In case we do not know which fields we want, we take them all.
|
||||
let use_item = match *item {
|
||||
None => false,
|
||||
Some((ref c, _)) => c.as_str().map_or(false, |key| self.fields.contains(&key)),
|
||||
};
|
||||
|
||||
if use_item {
|
||||
let (key, content) = item.take().unwrap();
|
||||
for entry in self.iter.by_ref() {
|
||||
if let Some((key, content)) = flat_map_take_entry(entry, self.fields) {
|
||||
self.pending_content = Some(content);
|
||||
return seed.deserialize(ContentDeserializer::new(key)).map(Some);
|
||||
}
|
||||
@@ -2916,44 +2953,24 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Claims one key-value pair from a FlatMapDeserializer's field buffer if the
|
||||
/// field name matches any of the recognized ones.
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
pub struct FlatInternallyTaggedAccess<'a, 'de: 'a, E> {
|
||||
iter: slice::IterMut<'a, Option<(Content<'de>, Content<'de>)>>,
|
||||
pending: Option<&'a Content<'de>>,
|
||||
_marker: PhantomData<E>,
|
||||
}
|
||||
fn flat_map_take_entry<'de>(
|
||||
entry: &mut Option<(Content<'de>, Content<'de>)>,
|
||||
recognized: &[&str],
|
||||
) -> Option<(Content<'de>, Content<'de>)> {
|
||||
// Entries in the FlatMapDeserializer buffer are nulled out as they get
|
||||
// claimed for deserialization. We only use an entry if it is still present
|
||||
// and if the field is one recognized by the current data structure.
|
||||
let is_recognized = match entry {
|
||||
None => false,
|
||||
Some((k, _v)) => k.as_str().map_or(false, |name| recognized.contains(&name)),
|
||||
};
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<'a, 'de, E> MapAccess<'de> for FlatInternallyTaggedAccess<'a, 'de, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn next_key_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||
where
|
||||
T: DeserializeSeed<'de>,
|
||||
{
|
||||
for item in &mut self.iter {
|
||||
if let Some((ref key, ref content)) = *item {
|
||||
// Do not take(), instead borrow this entry. The internally tagged
|
||||
// enum does its own buffering so we can't tell whether this entry
|
||||
// is going to be consumed. Borrowing here leaves the entry
|
||||
// available for later flattened fields.
|
||||
self.pending = Some(content);
|
||||
return seed.deserialize(ContentRefDeserializer::new(key)).map(Some);
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn next_value_seed<T>(&mut self, seed: T) -> Result<T::Value, Self::Error>
|
||||
where
|
||||
T: DeserializeSeed<'de>,
|
||||
{
|
||||
match self.pending.take() {
|
||||
Some(value) => seed.deserialize(ContentRefDeserializer::new(value)),
|
||||
None => panic!("value is missing"),
|
||||
}
|
||||
if is_recognized {
|
||||
entry.take()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#[cfg(serde_derive)]
|
||||
#[cfg(not(no_serde_derive))]
|
||||
pub mod de;
|
||||
#[cfg(serde_derive)]
|
||||
#[cfg(not(no_serde_derive))]
|
||||
pub mod ser;
|
||||
|
||||
pub mod size_hint;
|
||||
@@ -22,7 +22,7 @@ pub use self::string::from_utf8_lossy;
|
||||
#[cfg(any(feature = "alloc", feature = "std"))]
|
||||
pub use lib::{ToString, Vec};
|
||||
|
||||
#[cfg(core_try_from)]
|
||||
#[cfg(not(no_core_try_from))]
|
||||
pub use lib::convert::TryFrom;
|
||||
|
||||
mod string {
|
||||
|
||||
+22
-22
@@ -27,10 +27,10 @@ where
|
||||
T: Serialize,
|
||||
{
|
||||
value.serialize(TaggedSerializer {
|
||||
type_ident: type_ident,
|
||||
variant_ident: variant_ident,
|
||||
tag: tag,
|
||||
variant_name: variant_name,
|
||||
type_ident,
|
||||
variant_ident,
|
||||
tag,
|
||||
variant_name,
|
||||
delegate: serializer,
|
||||
})
|
||||
}
|
||||
@@ -51,7 +51,6 @@ enum Unsupported {
|
||||
String,
|
||||
ByteArray,
|
||||
Optional,
|
||||
Unit,
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
UnitStruct,
|
||||
Sequence,
|
||||
@@ -70,7 +69,6 @@ impl Display for Unsupported {
|
||||
Unsupported::String => formatter.write_str("a string"),
|
||||
Unsupported::ByteArray => formatter.write_str("a byte array"),
|
||||
Unsupported::Optional => formatter.write_str("an optional"),
|
||||
Unsupported::Unit => formatter.write_str("unit"),
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
Unsupported::UnitStruct => formatter.write_str("unit struct"),
|
||||
Unsupported::Sequence => formatter.write_str("a sequence"),
|
||||
@@ -184,7 +182,9 @@ where
|
||||
}
|
||||
|
||||
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
||||
Err(self.bad_type(Unsupported::Unit))
|
||||
let mut map = try!(self.delegate.serialize_map(Some(1)));
|
||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
||||
map.end()
|
||||
}
|
||||
|
||||
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
|
||||
@@ -350,8 +350,8 @@ mod content {
|
||||
impl<M> SerializeTupleVariantAsMapValue<M> {
|
||||
pub fn new(map: M, name: &'static str, len: usize) -> Self {
|
||||
SerializeTupleVariantAsMapValue {
|
||||
map: map,
|
||||
name: name,
|
||||
map,
|
||||
name,
|
||||
fields: Vec::with_capacity(len),
|
||||
}
|
||||
}
|
||||
@@ -390,8 +390,8 @@ mod content {
|
||||
impl<M> SerializeStructVariantAsMapValue<M> {
|
||||
pub fn new(map: M, name: &'static str, len: usize) -> Self {
|
||||
SerializeStructVariantAsMapValue {
|
||||
map: map,
|
||||
name: name,
|
||||
map,
|
||||
name,
|
||||
fields: Vec::with_capacity(len),
|
||||
}
|
||||
}
|
||||
@@ -525,7 +525,7 @@ mod content {
|
||||
Content::Map(ref entries) => {
|
||||
use ser::SerializeMap;
|
||||
let mut map = try!(serializer.serialize_map(Some(entries.len())));
|
||||
for &(ref k, ref v) in entries {
|
||||
for (k, v) in entries {
|
||||
try!(map.serialize_entry(k, v));
|
||||
}
|
||||
map.end()
|
||||
@@ -711,7 +711,7 @@ mod content {
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeTupleStruct, E> {
|
||||
Ok(SerializeTupleStruct {
|
||||
name: name,
|
||||
name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
@@ -725,9 +725,9 @@ mod content {
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeTupleVariant, E> {
|
||||
Ok(SerializeTupleVariant {
|
||||
name: name,
|
||||
variant_index: variant_index,
|
||||
variant: variant,
|
||||
name,
|
||||
variant_index,
|
||||
variant,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
@@ -747,7 +747,7 @@ mod content {
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeStruct, E> {
|
||||
Ok(SerializeStruct {
|
||||
name: name,
|
||||
name,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
@@ -761,9 +761,9 @@ mod content {
|
||||
len: usize,
|
||||
) -> Result<Self::SerializeStructVariant, E> {
|
||||
Ok(SerializeStructVariant {
|
||||
name: name,
|
||||
variant_index: variant_index,
|
||||
variant: variant,
|
||||
name,
|
||||
variant_index,
|
||||
variant,
|
||||
fields: Vec::with_capacity(len),
|
||||
error: PhantomData,
|
||||
})
|
||||
@@ -1273,8 +1273,8 @@ where
|
||||
{
|
||||
fn new(map: &'a mut M, name: &'static str) -> FlatMapSerializeStructVariantAsMapValue<'a, M> {
|
||||
FlatMapSerializeStructVariantAsMapValue {
|
||||
map: map,
|
||||
name: name,
|
||||
map,
|
||||
name,
|
||||
fields: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,17 @@ where
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[inline]
|
||||
pub fn cautious(hint: Option<usize>) -> usize {
|
||||
cmp::min(hint.unwrap_or(0), 4096)
|
||||
pub fn cautious<Element>(hint: Option<usize>) -> usize {
|
||||
const MAX_PREALLOC_BYTES: usize = 1024 * 1024;
|
||||
|
||||
if mem::size_of::<Element>() == 0 {
|
||||
0
|
||||
} else {
|
||||
cmp::min(
|
||||
hint.unwrap_or(0),
|
||||
MAX_PREALLOC_BYTES / mem::size_of::<Element>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
|
||||
|
||||
@@ -17,8 +17,9 @@ macro_rules! fmt_primitives {
|
||||
};
|
||||
}
|
||||
|
||||
/// ```edition2018
|
||||
/// use serde::Serialize;
|
||||
/// ```edition2021
|
||||
/// use serde::ser::Serialize;
|
||||
/// use serde_derive::Serialize;
|
||||
/// use std::fmt::{self, Display};
|
||||
///
|
||||
/// #[derive(Serialize)]
|
||||
|
||||
+114
-32
@@ -72,7 +72,7 @@ impl<'a> Serialize for fmt::Arguments<'a> {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", not(no_core_cstr)))]
|
||||
impl Serialize for CStr {
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
@@ -83,7 +83,7 @@ impl Serialize for CStr {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
|
||||
impl Serialize for CString {
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
@@ -182,9 +182,27 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(all(any(feature = "std", feature = "alloc"), not(no_relaxed_trait_bounds)))]
|
||||
macro_rules! seq_impl {
|
||||
($ty:ident < T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)* >) => {
|
||||
($ty:ident <T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)*>) => {
|
||||
impl<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.collect_seq(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(any(feature = "std", feature = "alloc"), no_relaxed_trait_bounds))]
|
||||
macro_rules! seq_impl {
|
||||
($ty:ident <T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)*>) => {
|
||||
impl<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
|
||||
where
|
||||
T: Serialize $(+ $tbound1 $(+ $tbound2)*)*,
|
||||
@@ -239,7 +257,24 @@ where
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(range_inclusive)]
|
||||
impl<Idx> Serialize for RangeFrom<Idx>
|
||||
where
|
||||
Idx: Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
use super::SerializeStruct;
|
||||
let mut state = try!(serializer.serialize_struct("RangeFrom", 1));
|
||||
try!(state.serialize_field("start", &self.start));
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(not(no_range_inclusive))]
|
||||
impl<Idx> Serialize for RangeInclusive<Idx>
|
||||
where
|
||||
Idx: Serialize,
|
||||
@@ -258,7 +293,24 @@ where
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(ops_bound, collections_bound))]
|
||||
impl<Idx> Serialize for RangeTo<Idx>
|
||||
where
|
||||
Idx: Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
use super::SerializeStruct;
|
||||
let mut state = try!(serializer.serialize_struct("RangeTo", 1));
|
||||
try!(state.serialize_field("end", &self.end));
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))]
|
||||
impl<T> Serialize for Bound<T>
|
||||
where
|
||||
T: Serialize,
|
||||
@@ -347,9 +399,28 @@ tuple_impls! {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[cfg(all(any(feature = "std", feature = "alloc"), not(no_relaxed_trait_bounds)))]
|
||||
macro_rules! map_impl {
|
||||
($ty:ident < K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)* >) => {
|
||||
($ty:ident <K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)*>) => {
|
||||
impl<K, V $(, $typaram)*> Serialize for $ty<K, V $(, $typaram)*>
|
||||
where
|
||||
K: Serialize,
|
||||
V: Serialize,
|
||||
{
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.collect_map(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(any(feature = "std", feature = "alloc"), no_relaxed_trait_bounds))]
|
||||
macro_rules! map_impl {
|
||||
($ty:ident <K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)*>) => {
|
||||
impl<K, V $(, $typaram)*> Serialize for $ty<K, V $(, $typaram)*>
|
||||
where
|
||||
K: Serialize $(+ $kbound1 $(+ $kbound2)*)*,
|
||||
@@ -465,9 +536,9 @@ where
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
macro_rules! nonzero_integers {
|
||||
( $( $T: ident, )+ ) => {
|
||||
($($T:ident,)+) => {
|
||||
$(
|
||||
#[cfg(num_nonzero)]
|
||||
#[cfg(not(no_num_nonzero))]
|
||||
impl Serialize for num::$T {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -488,7 +559,7 @@ nonzero_integers! {
|
||||
NonZeroUsize,
|
||||
}
|
||||
|
||||
#[cfg(num_nonzero_signed)]
|
||||
#[cfg(not(no_num_nonzero_signed))]
|
||||
nonzero_integers! {
|
||||
NonZeroI8,
|
||||
NonZeroI16,
|
||||
@@ -504,7 +575,7 @@ serde_if_integer128! {
|
||||
NonZeroU128,
|
||||
}
|
||||
|
||||
#[cfg(num_nonzero_signed)]
|
||||
#[cfg(not(no_num_nonzero_signed))]
|
||||
nonzero_integers! {
|
||||
NonZeroI128,
|
||||
}
|
||||
@@ -522,7 +593,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Serialize for RefCell<T>
|
||||
impl<T: ?Sized> Serialize for RefCell<T>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -538,7 +609,7 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T> Serialize for Mutex<T>
|
||||
impl<T: ?Sized> Serialize for Mutex<T>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -554,7 +625,7 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T> Serialize for RwLock<T>
|
||||
impl<T: ?Sized> Serialize for RwLock<T>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -591,7 +662,7 @@ where
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(any(core_duration, feature = "std"))]
|
||||
#[cfg(any(feature = "std", not(no_core_duration)))]
|
||||
impl Serialize for Duration {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -614,9 +685,10 @@ impl Serialize for SystemTime {
|
||||
S: Serializer,
|
||||
{
|
||||
use super::SerializeStruct;
|
||||
let duration_since_epoch = self
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map_err(|_| S::Error::custom("SystemTime must be later than UNIX_EPOCH"))?;
|
||||
let duration_since_epoch = match self.duration_since(UNIX_EPOCH) {
|
||||
Ok(duration_since_epoch) => duration_since_epoch,
|
||||
Err(_) => return Err(S::Error::custom("SystemTime must be later than UNIX_EPOCH")),
|
||||
};
|
||||
let mut state = try!(serializer.serialize_struct("SystemTime", 2));
|
||||
try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
|
||||
try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
|
||||
@@ -675,7 +747,7 @@ impl Serialize for net::IpAddr {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
const DEC_DIGITS_LUT: &'static [u8] = b"\
|
||||
const DEC_DIGITS_LUT: &[u8] = b"\
|
||||
0001020304050607080910111213141516171819\
|
||||
2021222324252627282930313233343536373839\
|
||||
4041424344454647484950515253545556575859\
|
||||
@@ -735,8 +807,9 @@ impl Serialize for net::Ipv4Addr {
|
||||
// Skip over delimiters that we initialized buf with
|
||||
written += format_u8(*oct, &mut buf[written + 1..]) + 1;
|
||||
}
|
||||
// We've only written ASCII bytes to the buffer, so it is valid UTF-8
|
||||
serializer.serialize_str(unsafe { str::from_utf8_unchecked(&buf[..written]) })
|
||||
// Safety: We've only written ASCII bytes to the buffer, so it is valid UTF-8
|
||||
let buf = unsafe { str::from_utf8_unchecked(&buf[..written]) };
|
||||
serializer.serialize_str(buf)
|
||||
} else {
|
||||
self.octets().serialize(serializer)
|
||||
}
|
||||
@@ -890,7 +963,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(core_reverse)]
|
||||
#[cfg(not(no_core_reverse))]
|
||||
impl<T> Serialize for Reverse<T>
|
||||
where
|
||||
T: Serialize,
|
||||
@@ -906,30 +979,39 @@ where
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[cfg(all(feature = "std", std_atomic))]
|
||||
#[cfg(all(feature = "std", not(no_std_atomic)))]
|
||||
macro_rules! atomic_impl {
|
||||
($($ty:ident)*) => {
|
||||
($($ty:ident $size:expr)*) => {
|
||||
$(
|
||||
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
|
||||
impl Serialize for $ty {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.load(Ordering::SeqCst).serialize(serializer)
|
||||
// Matches the atomic ordering used in libcore for the Debug impl
|
||||
self.load(Ordering::Relaxed).serialize(serializer)
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", std_atomic))]
|
||||
#[cfg(all(feature = "std", not(no_std_atomic)))]
|
||||
atomic_impl! {
|
||||
AtomicBool
|
||||
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
|
||||
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
|
||||
AtomicBool "8"
|
||||
AtomicI8 "8"
|
||||
AtomicI16 "16"
|
||||
AtomicI32 "32"
|
||||
AtomicIsize "ptr"
|
||||
AtomicU8 "8"
|
||||
AtomicU16 "16"
|
||||
AtomicU32 "32"
|
||||
AtomicUsize "ptr"
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "std", std_atomic64))]
|
||||
#[cfg(all(feature = "std", not(no_std_atomic64)))]
|
||||
atomic_impl! {
|
||||
AtomicI64 AtomicU64
|
||||
AtomicI64 "64"
|
||||
AtomicU64 "64"
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use ser::{
|
||||
/// [`SerializeTuple`], [`SerializeTupleStruct`], [`SerializeTupleVariant`],
|
||||
/// [`SerializeMap`], [`SerializeStruct`], and [`SerializeStructVariant`].
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::ser::{Serializer, Impossible};
|
||||
/// # use serde::__private::doc::Error;
|
||||
/// #
|
||||
|
||||
+74
-76
@@ -30,7 +30,7 @@
|
||||
//! # The Serializer trait
|
||||
//!
|
||||
//! [`Serializer`] implementations are provided by third-party crates, for
|
||||
//! example [`serde_json`], [`serde_yaml`] and [`bincode`].
|
||||
//! example [`serde_json`], [`serde_yaml`] and [`postcard`].
|
||||
//!
|
||||
//! A partial list of well-maintained formats is given on the [Serde
|
||||
//! website][data formats].
|
||||
@@ -99,7 +99,7 @@
|
||||
//! [`LinkedHashMap<K, V>`]: https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html
|
||||
//! [`Serialize`]: ../trait.Serialize.html
|
||||
//! [`Serializer`]: ../trait.Serializer.html
|
||||
//! [`bincode`]: https://github.com/servo/bincode
|
||||
//! [`postcard`]: https://github.com/jamesmunns/postcard
|
||||
//! [`linked-hash-map`]: https://crates.io/crates/linked-hash-map
|
||||
//! [`serde_derive`]: https://crates.io/crates/serde_derive
|
||||
//! [`serde_json`]: https://github.com/serde-rs/json
|
||||
@@ -115,10 +115,13 @@ mod impossible;
|
||||
|
||||
pub use self::impossible::Impossible;
|
||||
|
||||
#[cfg(all(feature = "unstable", not(feature = "std")))]
|
||||
#[doc(inline)]
|
||||
pub use core::error::Error as StdError;
|
||||
#[cfg(feature = "std")]
|
||||
#[doc(no_inline)]
|
||||
pub use std::error::Error as StdError;
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
||||
#[doc(no_inline)]
|
||||
pub use std_error::Error as StdError;
|
||||
|
||||
@@ -146,7 +149,7 @@ macro_rules! declare_error_trait {
|
||||
/// For example, a filesystem [`Path`] may refuse to serialize
|
||||
/// itself if it contains invalid UTF-8 data.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # struct Path;
|
||||
/// #
|
||||
/// # impl Path {
|
||||
@@ -191,8 +194,8 @@ declare_error_trait!(Error: Sized + Debug + Display);
|
||||
/// by Serde.
|
||||
///
|
||||
/// Serde provides `Serialize` implementations for many Rust primitive and
|
||||
/// standard library types. The complete list is [here][ser]. All of these can
|
||||
/// be serialized using Serde out of the box.
|
||||
/// standard library types. The complete list is [here][crate::ser]. All of
|
||||
/// these can be serialized using Serde out of the box.
|
||||
///
|
||||
/// Additionally, Serde provides a procedural macro called [`serde_derive`] to
|
||||
/// automatically generate `Serialize` implementations for structs and enums in
|
||||
@@ -212,14 +215,13 @@ declare_error_trait!(Error: Sized + Debug + Display);
|
||||
/// [`linked-hash-map`]: https://crates.io/crates/linked-hash-map
|
||||
/// [`serde_derive`]: https://crates.io/crates/serde_derive
|
||||
/// [derive section of the manual]: https://serde.rs/derive.html
|
||||
/// [ser]: https://docs.serde.rs/serde/ser/index.html
|
||||
pub trait Serialize {
|
||||
/// Serialize this value into the given Serde serializer.
|
||||
///
|
||||
/// See the [Implementing `Serialize`] section of the manual for more
|
||||
/// information about how to implement this method.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||
///
|
||||
/// struct Person {
|
||||
@@ -314,7 +316,7 @@ pub trait Serialize {
|
||||
/// - For example the `E::S` in `enum E { S { r: u8, g: u8, b: u8 } }`.
|
||||
///
|
||||
/// Many Serde serializers produce text or binary data as output, for example
|
||||
/// JSON or Bincode. This is not a requirement of the `Serializer` trait, and
|
||||
/// JSON or Postcard. This is not a requirement of the `Serializer` trait, and
|
||||
/// there are serializers that do not produce text or binary output. One example
|
||||
/// is the `serde_json::value::Serializer` (distinct from the main `serde_json`
|
||||
/// serializer) that produces a `serde_json::Value` data structure in memory as
|
||||
@@ -386,7 +388,7 @@ pub trait Serializer: Sized {
|
||||
|
||||
/// Serialize a `bool` value.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -408,7 +410,7 @@ pub trait Serializer: Sized {
|
||||
/// reasonable implementation would be to cast the value to `i64` and
|
||||
/// forward to `serialize_i64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -430,7 +432,7 @@ pub trait Serializer: Sized {
|
||||
/// reasonable implementation would be to cast the value to `i64` and
|
||||
/// forward to `serialize_i64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -452,7 +454,7 @@ pub trait Serializer: Sized {
|
||||
/// reasonable implementation would be to cast the value to `i64` and
|
||||
/// forward to `serialize_i64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -470,7 +472,7 @@ pub trait Serializer: Sized {
|
||||
|
||||
/// Serialize an `i64` value.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -489,7 +491,7 @@ pub trait Serializer: Sized {
|
||||
serde_if_integer128! {
|
||||
/// Serialize an `i128` value.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -518,7 +520,7 @@ pub trait Serializer: Sized {
|
||||
/// reasonable implementation would be to cast the value to `u64` and
|
||||
/// forward to `serialize_u64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -540,7 +542,7 @@ pub trait Serializer: Sized {
|
||||
/// reasonable implementation would be to cast the value to `u64` and
|
||||
/// forward to `serialize_u64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -562,7 +564,7 @@ pub trait Serializer: Sized {
|
||||
/// reasonable implementation would be to cast the value to `u64` and
|
||||
/// forward to `serialize_u64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -580,7 +582,7 @@ pub trait Serializer: Sized {
|
||||
|
||||
/// Serialize a `u64` value.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -599,7 +601,7 @@ pub trait Serializer: Sized {
|
||||
serde_if_integer128! {
|
||||
/// Serialize a `u128` value.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -628,7 +630,7 @@ pub trait Serializer: Sized {
|
||||
/// reasonable implementation would be to cast the value to `f64` and
|
||||
/// forward to `serialize_f64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -646,7 +648,7 @@ pub trait Serializer: Sized {
|
||||
|
||||
/// Serialize an `f64` value.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -667,7 +669,7 @@ pub trait Serializer: Sized {
|
||||
/// If the format does not support characters, it is reasonable to serialize
|
||||
/// it as a single element `str` or a `u32`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -685,7 +687,7 @@ pub trait Serializer: Sized {
|
||||
|
||||
/// Serialize a `&str`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -709,7 +711,7 @@ pub trait Serializer: Sized {
|
||||
/// `serialize_seq`. If forwarded, the implementation looks usually just
|
||||
/// like this:
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::ser::{Serializer, SerializeSeq};
|
||||
/// # use serde::__private::doc::Error;
|
||||
/// #
|
||||
@@ -738,7 +740,7 @@ pub trait Serializer: Sized {
|
||||
|
||||
/// Serialize a [`None`] value.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::{Serialize, Serializer};
|
||||
/// #
|
||||
/// # enum Option<T> {
|
||||
@@ -771,7 +773,7 @@ pub trait Serializer: Sized {
|
||||
|
||||
/// Serialize a [`Some(T)`] value.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::{Serialize, Serializer};
|
||||
/// #
|
||||
/// # enum Option<T> {
|
||||
@@ -806,7 +808,7 @@ pub trait Serializer: Sized {
|
||||
|
||||
/// Serialize a `()` value.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde::Serializer;
|
||||
/// #
|
||||
/// # serde::__private_serialize!();
|
||||
@@ -826,7 +828,7 @@ pub trait Serializer: Sized {
|
||||
///
|
||||
/// A reasonable implementation would be to forward to `serialize_unit`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::{Serialize, Serializer};
|
||||
///
|
||||
/// struct Nothing;
|
||||
@@ -848,7 +850,7 @@ pub trait Serializer: Sized {
|
||||
/// this variant within the enum, and the `variant` is the name of the
|
||||
/// variant.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::{Serialize, Serializer};
|
||||
///
|
||||
/// enum E {
|
||||
@@ -881,7 +883,7 @@ pub trait Serializer: Sized {
|
||||
/// wrappers around the data they contain. A reasonable implementation would
|
||||
/// be to forward to `value.serialize(self)`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::{Serialize, Serializer};
|
||||
///
|
||||
/// struct Millimeters(u8);
|
||||
@@ -909,7 +911,7 @@ pub trait Serializer: Sized {
|
||||
/// this variant within the enum, and the `variant` is the name of the
|
||||
/// variant. The `value` is the data contained within this newtype variant.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::{Serialize, Serializer};
|
||||
///
|
||||
/// enum E {
|
||||
@@ -947,7 +949,7 @@ pub trait Serializer: Sized {
|
||||
/// not be computable before the sequence is iterated. Some serializers only
|
||||
/// support sequences whose length is known up front.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::marker::PhantomData;
|
||||
/// #
|
||||
/// # struct Vec<T>(PhantomData<T>);
|
||||
@@ -960,14 +962,14 @@ pub trait Serializer: Sized {
|
||||
/// #
|
||||
/// # impl<'a, T> IntoIterator for &'a Vec<T> {
|
||||
/// # type Item = &'a T;
|
||||
/// # type IntoIter = Box<Iterator<Item = &'a T>>;
|
||||
/// # type IntoIter = Box<dyn Iterator<Item = &'a T>>;
|
||||
/// #
|
||||
/// # fn into_iter(self) -> Self::IntoIter {
|
||||
/// # unimplemented!()
|
||||
/// # }
|
||||
/// # }
|
||||
/// #
|
||||
/// use serde::ser::{Serialize, Serializer, SerializeSeq};
|
||||
/// use serde::ser::{Serialize, SerializeSeq, Serializer};
|
||||
///
|
||||
/// impl<T> Serialize for Vec<T>
|
||||
/// where
|
||||
@@ -992,8 +994,8 @@ pub trait Serializer: Sized {
|
||||
/// This call must be followed by zero or more calls to `serialize_element`,
|
||||
/// then a call to `end`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||
///
|
||||
/// # mod fool {
|
||||
/// # trait Serialize {}
|
||||
@@ -1022,7 +1024,7 @@ pub trait Serializer: Sized {
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||
///
|
||||
/// const VRAM_SIZE: usize = 386;
|
||||
@@ -1050,7 +1052,7 @@ pub trait Serializer: Sized {
|
||||
/// The `name` is the name of the tuple struct and the `len` is the number
|
||||
/// of data fields that will be serialized.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
||||
///
|
||||
/// struct Rgb(u8, u8, u8);
|
||||
@@ -1082,7 +1084,7 @@ pub trait Serializer: Sized {
|
||||
/// this variant within the enum, the `variant` is the name of the variant,
|
||||
/// and the `len` is the number of data fields that will be serialized.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
||||
///
|
||||
/// enum E {
|
||||
@@ -1128,7 +1130,7 @@ pub trait Serializer: Sized {
|
||||
/// be computable before the map is iterated. Some serializers only support
|
||||
/// maps whose length is known up front.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::marker::PhantomData;
|
||||
/// #
|
||||
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
||||
@@ -1141,14 +1143,14 @@ pub trait Serializer: Sized {
|
||||
/// #
|
||||
/// # impl<'a, K, V> IntoIterator for &'a HashMap<K, V> {
|
||||
/// # type Item = (&'a K, &'a V);
|
||||
/// # type IntoIter = Box<Iterator<Item = (&'a K, &'a V)>>;
|
||||
/// # type IntoIter = Box<dyn Iterator<Item = (&'a K, &'a V)>>;
|
||||
/// #
|
||||
/// # fn into_iter(self) -> Self::IntoIter {
|
||||
/// # unimplemented!()
|
||||
/// # }
|
||||
/// # }
|
||||
/// #
|
||||
/// use serde::ser::{Serialize, Serializer, SerializeMap};
|
||||
/// use serde::ser::{Serialize, SerializeMap, Serializer};
|
||||
///
|
||||
/// impl<K, V> Serialize for HashMap<K, V>
|
||||
/// where
|
||||
@@ -1176,7 +1178,7 @@ pub trait Serializer: Sized {
|
||||
/// The `name` is the name of the struct and the `len` is the number of
|
||||
/// data fields that will be serialized.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||
///
|
||||
/// struct Rgb {
|
||||
@@ -1212,7 +1214,7 @@ pub trait Serializer: Sized {
|
||||
/// this variant within the enum, the `variant` is the name of the variant,
|
||||
/// and the `len` is the number of data fields that will be serialized.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
||||
///
|
||||
/// enum E {
|
||||
@@ -1254,7 +1256,7 @@ pub trait Serializer: Sized {
|
||||
/// using [`serialize_seq`]. Implementors should not need to override this
|
||||
/// method.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::{Serialize, Serializer};
|
||||
///
|
||||
/// struct SecretlyOneHigher {
|
||||
@@ -1280,13 +1282,13 @@ pub trait Serializer: Sized {
|
||||
let iter = iter.into_iter();
|
||||
let mut serializer = try!(self.serialize_seq(iterator_len_hint(&iter)));
|
||||
|
||||
#[cfg(iterator_try_fold)]
|
||||
#[cfg(not(no_iterator_try_fold))]
|
||||
{
|
||||
let mut iter = iter;
|
||||
try!(iter.try_for_each(|item| serializer.serialize_element(&item)));
|
||||
}
|
||||
|
||||
#[cfg(not(iterator_try_fold))]
|
||||
#[cfg(no_iterator_try_fold)]
|
||||
{
|
||||
for item in iter {
|
||||
try!(serializer.serialize_element(&item));
|
||||
@@ -1302,7 +1304,7 @@ pub trait Serializer: Sized {
|
||||
/// using [`serialize_map`]. Implementors should not need to override this
|
||||
/// method.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::{Serialize, Serializer};
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
@@ -1331,13 +1333,13 @@ pub trait Serializer: Sized {
|
||||
let iter = iter.into_iter();
|
||||
let mut serializer = try!(self.serialize_map(iterator_len_hint(&iter)));
|
||||
|
||||
#[cfg(iterator_try_fold)]
|
||||
#[cfg(not(no_iterator_try_fold))]
|
||||
{
|
||||
let mut iter = iter;
|
||||
try!(iter.try_for_each(|(key, value)| serializer.serialize_entry(&key, &value)));
|
||||
}
|
||||
|
||||
#[cfg(not(iterator_try_fold))]
|
||||
#[cfg(no_iterator_try_fold)]
|
||||
{
|
||||
for (key, value) in iter {
|
||||
try!(serializer.serialize_entry(&key, &value));
|
||||
@@ -1353,7 +1355,7 @@ pub trait Serializer: Sized {
|
||||
/// delegates to [`serialize_str`]. Serializers are encouraged to provide a
|
||||
/// more efficient implementation if possible.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # struct DateTime;
|
||||
/// #
|
||||
/// # impl DateTime {
|
||||
@@ -1368,9 +1370,7 @@ pub trait Serializer: Sized {
|
||||
/// where
|
||||
/// S: Serializer,
|
||||
/// {
|
||||
/// serializer.collect_str(&format_args!("{:?}{:?}",
|
||||
/// self.naive_local(),
|
||||
/// self.offset()))
|
||||
/// serializer.collect_str(&format_args!("{:?}{:?}", self.naive_local(), self.offset()))
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
@@ -1391,7 +1391,7 @@ pub trait Serializer: Sized {
|
||||
/// of this method. If no more sensible behavior is possible, the
|
||||
/// implementation is expected to return an error.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # struct DateTime;
|
||||
/// #
|
||||
/// # impl DateTime {
|
||||
@@ -1406,9 +1406,7 @@ pub trait Serializer: Sized {
|
||||
/// where
|
||||
/// S: Serializer,
|
||||
/// {
|
||||
/// serializer.collect_str(&format_args!("{:?}{:?}",
|
||||
/// self.naive_local(),
|
||||
/// self.offset()))
|
||||
/// serializer.collect_str(&format_args!("{:?}{:?}", self.naive_local(), self.offset()))
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
@@ -1423,10 +1421,10 @@ pub trait Serializer: Sized {
|
||||
/// Some types have a human-readable form that may be somewhat expensive to
|
||||
/// construct, as well as a binary form that is compact and efficient.
|
||||
/// Generally text-based formats like JSON and YAML will prefer to use the
|
||||
/// human-readable one and binary formats like Bincode will prefer the
|
||||
/// human-readable one and binary formats like Postcard will prefer the
|
||||
/// compact one.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::fmt::{self, Display};
|
||||
/// #
|
||||
/// # struct Timestamp;
|
||||
@@ -1475,7 +1473,7 @@ pub trait Serializer: Sized {
|
||||
///
|
||||
/// # Example use
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::marker::PhantomData;
|
||||
/// #
|
||||
/// # struct Vec<T>(PhantomData<T>);
|
||||
@@ -1488,13 +1486,13 @@ pub trait Serializer: Sized {
|
||||
/// #
|
||||
/// # impl<'a, T> IntoIterator for &'a Vec<T> {
|
||||
/// # type Item = &'a T;
|
||||
/// # type IntoIter = Box<Iterator<Item = &'a T>>;
|
||||
/// # type IntoIter = Box<dyn Iterator<Item = &'a T>>;
|
||||
/// # fn into_iter(self) -> Self::IntoIter {
|
||||
/// # unimplemented!()
|
||||
/// # }
|
||||
/// # }
|
||||
/// #
|
||||
/// use serde::ser::{Serialize, Serializer, SerializeSeq};
|
||||
/// use serde::ser::{Serialize, SerializeSeq, Serializer};
|
||||
///
|
||||
/// impl<T> Serialize for Vec<T>
|
||||
/// where
|
||||
@@ -1539,8 +1537,8 @@ pub trait SerializeSeq {
|
||||
///
|
||||
/// # Example use
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||
///
|
||||
/// # mod fool {
|
||||
/// # trait Serialize {}
|
||||
@@ -1569,7 +1567,7 @@ pub trait SerializeSeq {
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::marker::PhantomData;
|
||||
/// #
|
||||
/// # struct Array<T>(PhantomData<T>);
|
||||
@@ -1582,13 +1580,13 @@ pub trait SerializeSeq {
|
||||
/// #
|
||||
/// # impl<'a, T> IntoIterator for &'a Array<T> {
|
||||
/// # type Item = &'a T;
|
||||
/// # type IntoIter = Box<Iterator<Item = &'a T>>;
|
||||
/// # type IntoIter = Box<dyn Iterator<Item = &'a T>>;
|
||||
/// # fn into_iter(self) -> Self::IntoIter {
|
||||
/// # unimplemented!()
|
||||
/// # }
|
||||
/// # }
|
||||
/// #
|
||||
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
||||
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||
///
|
||||
/// # mod fool {
|
||||
/// # trait Serialize {}
|
||||
@@ -1639,7 +1637,7 @@ pub trait SerializeTuple {
|
||||
///
|
||||
/// # Example use
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
||||
///
|
||||
/// struct Rgb(u8, u8, u8);
|
||||
@@ -1684,7 +1682,7 @@ pub trait SerializeTupleStruct {
|
||||
///
|
||||
/// # Example use
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
||||
///
|
||||
/// enum E {
|
||||
@@ -1742,7 +1740,7 @@ pub trait SerializeTupleVariant {
|
||||
///
|
||||
/// # Example use
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use std::marker::PhantomData;
|
||||
/// #
|
||||
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
||||
@@ -1755,14 +1753,14 @@ pub trait SerializeTupleVariant {
|
||||
/// #
|
||||
/// # impl<'a, K, V> IntoIterator for &'a HashMap<K, V> {
|
||||
/// # type Item = (&'a K, &'a V);
|
||||
/// # type IntoIter = Box<Iterator<Item = (&'a K, &'a V)>>;
|
||||
/// # type IntoIter = Box<dyn Iterator<Item = (&'a K, &'a V)>>;
|
||||
/// #
|
||||
/// # fn into_iter(self) -> Self::IntoIter {
|
||||
/// # unimplemented!()
|
||||
/// # }
|
||||
/// # }
|
||||
/// #
|
||||
/// use serde::ser::{Serialize, Serializer, SerializeMap};
|
||||
/// use serde::ser::{Serialize, SerializeMap, Serializer};
|
||||
///
|
||||
/// impl<K, V> Serialize for HashMap<K, V>
|
||||
/// where
|
||||
@@ -1853,7 +1851,7 @@ pub trait SerializeMap {
|
||||
///
|
||||
/// # Example use
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||
///
|
||||
/// struct Rgb {
|
||||
@@ -1913,7 +1911,7 @@ pub trait SerializeStruct {
|
||||
///
|
||||
/// # Example use
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
||||
///
|
||||
/// enum E {
|
||||
|
||||
@@ -9,7 +9,7 @@ use lib::{Debug, Display};
|
||||
/// generally provide their error types with a `std::error::Error` impl
|
||||
/// directly:
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// #[derive(Debug)]
|
||||
/// struct MySerError {...}
|
||||
///
|
||||
@@ -29,7 +29,7 @@ use lib::{Debug, Display};
|
||||
/// std = ["serde/std"]
|
||||
/// ```
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// #[cfg(feature = "std")]
|
||||
/// impl std::error::Error for MySerError {}
|
||||
/// ```
|
||||
@@ -37,7 +37,7 @@ use lib::{Debug, Display};
|
||||
/// ... or else provide the std Error impl unconditionally via Serde's
|
||||
/// re-export:
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// impl serde::ser::StdError for MySerError {}
|
||||
/// ```
|
||||
pub trait Error: Debug + Display {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
[package]
|
||||
name = "serde_derive"
|
||||
version = "1.0.130" # remember to update html_root_url
|
||||
version = "1.0.172" # remember to update html_root_url
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
categories = ["no-std", "no-std::no-alloc"]
|
||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||
homepage = "https://serde.rs"
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
documentation = "https://serde.rs/derive.html"
|
||||
keywords = ["serde", "serialization", "no_std"]
|
||||
homepage = "https://serde.rs"
|
||||
keywords = ["serde", "serialization", "no_std", "derive"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
readme = "crates-io.md"
|
||||
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
rust-version = "1.56"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
@@ -22,10 +23,10 @@ proc-macro = true
|
||||
[dependencies]
|
||||
proc-macro2 = "1.0"
|
||||
quote = "1.0"
|
||||
syn = "1.0.60"
|
||||
syn = "2.0.25"
|
||||
|
||||
[dev-dependencies]
|
||||
serde = { version = "1.0", path = "../serde" }
|
||||
serde = { version = "1", path = "../serde" }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
use std::env;
|
||||
use std::process::Command;
|
||||
use std::str;
|
||||
|
||||
// The rustc-cfg strings below are *not* public API. Please let us know by
|
||||
// opening a GitHub issue if your build environment requires some way to enable
|
||||
// these cfgs other than by executing our build script.
|
||||
fn main() {
|
||||
let minor = match rustc_minor_version() {
|
||||
Some(minor) => minor,
|
||||
None => return,
|
||||
};
|
||||
|
||||
// Underscore const names stabilized in Rust 1.37:
|
||||
// https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html#using-unnamed-const-items-for-macros
|
||||
if minor >= 37 {
|
||||
println!("cargo:rustc-cfg=underscore_consts");
|
||||
}
|
||||
|
||||
// The ptr::addr_of! macro stabilized in Rust 1.51:
|
||||
// https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#stabilized-apis
|
||||
if minor >= 51 {
|
||||
println!("cargo:rustc-cfg=ptr_addr_of");
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
+17
-11
@@ -50,7 +50,7 @@ pub fn with_where_predicates_from_fields(
|
||||
.data
|
||||
.all_fields()
|
||||
.filter_map(|field| from_field(&field.attrs))
|
||||
.flat_map(|predicates| predicates.to_vec());
|
||||
.flat_map(<[syn::WherePredicate]>::to_vec);
|
||||
|
||||
let mut generics = generics.clone();
|
||||
generics.make_where_clause().predicates.extend(predicates);
|
||||
@@ -72,7 +72,7 @@ pub fn with_where_predicates_from_variants(
|
||||
let predicates = variants
|
||||
.iter()
|
||||
.filter_map(|variant| from_variant(&variant.attrs))
|
||||
.flat_map(|predicates| predicates.to_vec());
|
||||
.flat_map(<[syn::WherePredicate]>::to_vec);
|
||||
|
||||
let mut generics = generics.clone();
|
||||
generics.make_where_clause().predicates.extend(predicates);
|
||||
@@ -184,9 +184,7 @@ pub fn with_bound(
|
||||
|
||||
syn::Type::Infer(_) | syn::Type::Never(_) | syn::Type::Verbatim(_) => {}
|
||||
|
||||
#[cfg(test)]
|
||||
syn::Type::__TestExhaustive(_) => unimplemented!(),
|
||||
#[cfg(not(test))]
|
||||
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -202,10 +200,16 @@ pub fn with_bound(
|
||||
for arg in &arguments.args {
|
||||
match arg {
|
||||
syn::GenericArgument::Type(arg) => self.visit_type(arg),
|
||||
syn::GenericArgument::Binding(arg) => self.visit_type(&arg.ty),
|
||||
syn::GenericArgument::AssocType(arg) => self.visit_type(&arg.ty),
|
||||
syn::GenericArgument::Lifetime(_)
|
||||
| syn::GenericArgument::Constraint(_)
|
||||
| syn::GenericArgument::Const(_) => {}
|
||||
| syn::GenericArgument::Const(_)
|
||||
| syn::GenericArgument::AssocConst(_)
|
||||
| syn::GenericArgument::Constraint(_) => {}
|
||||
#[cfg_attr(
|
||||
all(test, exhaustive),
|
||||
deny(non_exhaustive_omitted_patterns)
|
||||
)]
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,7 +232,9 @@ pub fn with_bound(
|
||||
fn visit_type_param_bound(&mut self, bound: &'ast syn::TypeParamBound) {
|
||||
match bound {
|
||||
syn::TypeParamBound::Trait(bound) => self.visit_path(&bound.path),
|
||||
syn::TypeParamBound::Lifetime(_) => {}
|
||||
syn::TypeParamBound::Lifetime(_) | syn::TypeParamBound::Verbatim(_) => {}
|
||||
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +259,7 @@ pub fn with_bound(
|
||||
};
|
||||
match &cont.data {
|
||||
Data::Enum(variants) => {
|
||||
for variant in variants.iter() {
|
||||
for variant in variants {
|
||||
let relevant_fields = variant
|
||||
.fields
|
||||
.iter()
|
||||
@@ -336,7 +342,7 @@ pub fn with_self_bound(
|
||||
|
||||
pub fn with_lifetime_bound(generics: &syn::Generics, lifetime: &str) -> syn::Generics {
|
||||
let bound = syn::Lifetime::new(lifetime, Span::call_site());
|
||||
let def = syn::LifetimeDef {
|
||||
let def = syn::LifetimeParam {
|
||||
attrs: Vec::new(),
|
||||
lifetime: bound.clone(),
|
||||
colon_token: None,
|
||||
|
||||
+400
-337
File diff suppressed because it is too large
Load Diff
@@ -1,23 +1,11 @@
|
||||
use proc_macro2::{Ident, TokenStream};
|
||||
use quote::format_ident;
|
||||
use proc_macro2::TokenStream;
|
||||
|
||||
use syn;
|
||||
use try;
|
||||
|
||||
pub fn wrap_in_const(
|
||||
serde_path: Option<&syn::Path>,
|
||||
trait_: &str,
|
||||
ty: &Ident,
|
||||
code: TokenStream,
|
||||
) -> TokenStream {
|
||||
pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> TokenStream {
|
||||
let try_replacement = try::replacement();
|
||||
|
||||
let dummy_const = if cfg!(underscore_consts) {
|
||||
format_ident!("_")
|
||||
} else {
|
||||
format_ident!("_IMPL_{}_FOR_{}", trait_, unraw(ty))
|
||||
};
|
||||
|
||||
let use_serde = match serde_path {
|
||||
Some(path) => quote! {
|
||||
use #path as _serde;
|
||||
@@ -31,18 +19,10 @@ pub fn wrap_in_const(
|
||||
quote! {
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const #dummy_const: () = {
|
||||
const _: () = {
|
||||
#use_serde
|
||||
#try_replacement
|
||||
#code
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
fn unraw(ident: &Ident) -> String {
|
||||
// str::trim_start_matches was added in 1.30, trim_left_matches deprecated
|
||||
// in 1.33. We currently support rustc back to 1.15 so we need to continue
|
||||
// to use the deprecated one.
|
||||
ident.to_string().trim_left_matches("r#").to_owned()
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ fn enum_from_ast<'a>(
|
||||
variants: &'a Punctuated<syn::Variant, Token![,]>,
|
||||
container_default: &attr::Default,
|
||||
) -> Vec<Variant<'a>> {
|
||||
variants
|
||||
let variants: Vec<Variant> = variants
|
||||
.iter()
|
||||
.map(|variant| {
|
||||
let attrs = attr::Variant::from_ast(cx, variant);
|
||||
@@ -154,7 +154,20 @@ fn enum_from_ast<'a>(
|
||||
original: variant,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
.collect();
|
||||
|
||||
let index_of_last_tagged_variant = variants
|
||||
.iter()
|
||||
.rposition(|variant| !variant.attrs.untagged());
|
||||
if let Some(index_of_last_tagged_variant) = index_of_last_tagged_variant {
|
||||
for variant in &variants[..index_of_last_tagged_variant] {
|
||||
if variant.attrs.untagged() {
|
||||
cx.error_spanned_by(&variant.ident, "all variants with the #[serde(untagged)] attribute must be placed at the end of the enum");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variants
|
||||
}
|
||||
|
||||
fn struct_from_ast<'a>(
|
||||
|
||||
+591
-733
File diff suppressed because it is too large
Load Diff
@@ -3,9 +3,10 @@ use internals::attr::{Identifier, TagType};
|
||||
use internals::{ungroup, Ctxt, Derive};
|
||||
use syn::{Member, Type};
|
||||
|
||||
/// Cross-cutting checks that require looking at more than a single attrs
|
||||
/// object. Simpler checks should happen when parsing and building the attrs.
|
||||
// Cross-cutting checks that require looking at more than a single attrs object.
|
||||
// Simpler checks should happen when parsing and building the attrs.
|
||||
pub fn check(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
||||
check_remote_generic(cx, cont);
|
||||
check_getter(cx, cont);
|
||||
check_flatten(cx, cont);
|
||||
check_identifier(cx, cont);
|
||||
@@ -16,8 +17,30 @@ pub fn check(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
||||
check_from_and_try_from(cx, cont);
|
||||
}
|
||||
|
||||
/// Getters are only allowed inside structs (not enums) with the `remote`
|
||||
/// attribute.
|
||||
// Remote derive definition type must have either all of the generics of the
|
||||
// remote type:
|
||||
//
|
||||
// #[serde(remote = "Generic")]
|
||||
// struct Generic<T> {…}
|
||||
//
|
||||
// or none of them, i.e. defining impls for one concrete instantiation of the
|
||||
// remote type only:
|
||||
//
|
||||
// #[serde(remote = "Generic<T>")]
|
||||
// struct ConcreteDef {…}
|
||||
//
|
||||
fn check_remote_generic(cx: &Ctxt, cont: &Container) {
|
||||
if let Some(remote) = cont.attrs.remote() {
|
||||
let local_has_generic = !cont.generics.params.is_empty();
|
||||
let remote_has_generic = !remote.segments.last().unwrap().arguments.is_none();
|
||||
if local_has_generic && remote_has_generic {
|
||||
cx.error_spanned_by(remote, "remove generic parameters from this path");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Getters are only allowed inside structs (not enums) with the `remote`
|
||||
// attribute.
|
||||
fn check_getter(cx: &Ctxt, cont: &Container) {
|
||||
match cont.data {
|
||||
Data::Enum(_) => {
|
||||
@@ -39,7 +62,7 @@ fn check_getter(cx: &Ctxt, cont: &Container) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Flattening has some restrictions we can test.
|
||||
// Flattening has some restrictions we can test.
|
||||
fn check_flatten(cx: &Ctxt, cont: &Container) {
|
||||
match &cont.data {
|
||||
Data::Enum(variants) => {
|
||||
@@ -78,18 +101,16 @@ fn check_flatten_field(cx: &Ctxt, style: Style, field: &Field) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The `other` attribute must be used at most once and it must be the last
|
||||
/// variant of an enum.
|
||||
///
|
||||
/// Inside a `variant_identifier` all variants must be unit variants. Inside a
|
||||
/// `field_identifier` all but possibly one variant must be unit variants. The
|
||||
/// last variant may be a newtype variant which is an implicit "other" case.
|
||||
// The `other` attribute must be used at most once and it must be the last
|
||||
// variant of an enum.
|
||||
//
|
||||
// Inside a `variant_identifier` all variants must be unit variants. Inside a
|
||||
// `field_identifier` all but possibly one variant must be unit variants. The
|
||||
// last variant may be a newtype variant which is an implicit "other" case.
|
||||
fn check_identifier(cx: &Ctxt, cont: &Container) {
|
||||
let variants = match &cont.data {
|
||||
Data::Enum(variants) => variants,
|
||||
Data::Struct(_, _) => {
|
||||
return;
|
||||
}
|
||||
Data::Struct(_, _) => return,
|
||||
};
|
||||
|
||||
for (i, variant) in variants.iter().enumerate() {
|
||||
@@ -166,17 +187,15 @@ fn check_identifier(cx: &Ctxt, cont: &Container) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Skip-(de)serializing attributes are not allowed on variants marked
|
||||
/// (de)serialize_with.
|
||||
// Skip-(de)serializing attributes are not allowed on variants marked
|
||||
// (de)serialize_with.
|
||||
fn check_variant_skip_attrs(cx: &Ctxt, cont: &Container) {
|
||||
let variants = match &cont.data {
|
||||
Data::Enum(variants) => variants,
|
||||
Data::Struct(_, _) => {
|
||||
return;
|
||||
}
|
||||
Data::Struct(_, _) => return,
|
||||
};
|
||||
|
||||
for variant in variants.iter() {
|
||||
for variant in variants {
|
||||
if variant.attrs.serialize_with().is_some() {
|
||||
if variant.attrs.skip_serializing() {
|
||||
cx.error_spanned_by(
|
||||
@@ -241,10 +260,9 @@ fn check_variant_skip_attrs(cx: &Ctxt, cont: &Container) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The tag of an internally-tagged struct variant must not be
|
||||
/// the same as either one of its fields, as this would result in
|
||||
/// duplicate keys in the serialized output and/or ambiguity in
|
||||
/// the to-be-deserialized input.
|
||||
// The tag of an internally-tagged struct variant must not be the same as either
|
||||
// one of its fields, as this would result in duplicate keys in the serialized
|
||||
// output and/or ambiguity in the to-be-deserialized input.
|
||||
fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
|
||||
let variants = match &cont.data {
|
||||
Data::Enum(variants) => variants,
|
||||
@@ -290,8 +308,8 @@ fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
|
||||
}
|
||||
}
|
||||
|
||||
/// In the case of adjacently-tagged enums, the type and the
|
||||
/// contents tag must differ, for the same reason.
|
||||
// In the case of adjacently-tagged enums, the type and the contents tag must
|
||||
// differ, for the same reason.
|
||||
fn check_adjacent_tag_conflict(cx: &Ctxt, cont: &Container) {
|
||||
let (type_tag, content_tag) = match cont.attrs.tag() {
|
||||
TagType::Adjacent { tag, content } => (tag, content),
|
||||
@@ -309,7 +327,7 @@ fn check_adjacent_tag_conflict(cx: &Ctxt, cont: &Container) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Enums and unit structs cannot be transparent.
|
||||
// Enums and unit structs cannot be transparent.
|
||||
fn check_transparent(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
||||
if !cont.attrs.transparent() {
|
||||
return;
|
||||
|
||||
@@ -44,12 +44,19 @@ impl Ctxt {
|
||||
}
|
||||
|
||||
/// Consume this object, producing a formatted error string if there are errors.
|
||||
pub fn check(self) -> Result<(), Vec<syn::Error>> {
|
||||
let errors = self.errors.borrow_mut().take().unwrap();
|
||||
match errors.len() {
|
||||
0 => Ok(()),
|
||||
_ => Err(errors),
|
||||
pub fn check(self) -> syn::Result<()> {
|
||||
let mut errors = self.errors.borrow_mut().take().unwrap().into_iter();
|
||||
|
||||
let mut combined = match errors.next() {
|
||||
Some(first) => first,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
for rest in errors {
|
||||
combined.combine(rest);
|
||||
}
|
||||
|
||||
Err(combined)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,9 +147,7 @@ impl ReplaceReceiver<'_> {
|
||||
|
||||
Type::Infer(_) | Type::Never(_) | Type::Verbatim(_) => {}
|
||||
|
||||
#[cfg(test)]
|
||||
Type::__TestExhaustive(_) => unimplemented!(),
|
||||
#[cfg(not(test))]
|
||||
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -181,10 +179,13 @@ impl ReplaceReceiver<'_> {
|
||||
for arg in &mut arguments.args {
|
||||
match arg {
|
||||
GenericArgument::Type(arg) => self.visit_type_mut(arg),
|
||||
GenericArgument::Binding(arg) => self.visit_type_mut(&mut arg.ty),
|
||||
GenericArgument::AssocType(arg) => self.visit_type_mut(&mut arg.ty),
|
||||
GenericArgument::Lifetime(_)
|
||||
| GenericArgument::Constraint(_)
|
||||
| GenericArgument::Const(_) => {}
|
||||
| GenericArgument::Const(_)
|
||||
| GenericArgument::AssocConst(_)
|
||||
| GenericArgument::Constraint(_) => {}
|
||||
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,7 +208,9 @@ impl ReplaceReceiver<'_> {
|
||||
fn visit_type_param_bound_mut(&mut self, bound: &mut TypeParamBound) {
|
||||
match bound {
|
||||
TypeParamBound::Trait(bound) => self.visit_path_mut(&mut bound.path),
|
||||
TypeParamBound::Lifetime(_) => {}
|
||||
TypeParamBound::Lifetime(_) | TypeParamBound::Verbatim(_) => {}
|
||||
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +234,9 @@ impl ReplaceReceiver<'_> {
|
||||
self.visit_type_param_bound_mut(bound);
|
||||
}
|
||||
}
|
||||
WherePredicate::Lifetime(_) | WherePredicate::Eq(_) => {}
|
||||
WherePredicate::Lifetime(_) => {}
|
||||
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ pub const DEFAULT: Symbol = Symbol("default");
|
||||
pub const DENY_UNKNOWN_FIELDS: Symbol = Symbol("deny_unknown_fields");
|
||||
pub const DESERIALIZE: Symbol = Symbol("deserialize");
|
||||
pub const DESERIALIZE_WITH: Symbol = Symbol("deserialize_with");
|
||||
pub const EXPECTING: Symbol = Symbol("expecting");
|
||||
pub const FIELD_IDENTIFIER: Symbol = Symbol("field_identifier");
|
||||
pub const FLATTEN: Symbol = Symbol("flatten");
|
||||
pub const FROM: Symbol = Symbol("from");
|
||||
@@ -22,6 +23,7 @@ pub const OTHER: Symbol = Symbol("other");
|
||||
pub const REMOTE: Symbol = Symbol("remote");
|
||||
pub const RENAME: Symbol = Symbol("rename");
|
||||
pub const RENAME_ALL: Symbol = Symbol("rename_all");
|
||||
pub const REPR: Symbol = Symbol("repr");
|
||||
pub const SERDE: Symbol = Symbol("serde");
|
||||
pub const SERIALIZE: Symbol = Symbol("serialize");
|
||||
pub const SERIALIZE_WITH: Symbol = Symbol("serialize_with");
|
||||
@@ -35,7 +37,6 @@ pub const TRY_FROM: Symbol = Symbol("try_from");
|
||||
pub const UNTAGGED: Symbol = Symbol("untagged");
|
||||
pub const VARIANT_IDENTIFIER: Symbol = Symbol("variant_identifier");
|
||||
pub const WITH: Symbol = Symbol("with");
|
||||
pub const EXPECTING: Symbol = Symbol("expecting");
|
||||
|
||||
impl PartialEq<Symbol> for Ident {
|
||||
fn eq(&self, word: &Symbol) -> bool {
|
||||
|
||||
+31
-14
@@ -1,7 +1,7 @@
|
||||
//! This crate provides Serde's two derive macros.
|
||||
//!
|
||||
//! ```edition2018
|
||||
//! # use serde_derive::{Serialize, Deserialize};
|
||||
//! ```edition2021
|
||||
//! # use serde_derive::{Deserialize, Serialize};
|
||||
//! #
|
||||
//! #[derive(Serialize, Deserialize)]
|
||||
//! # struct S;
|
||||
@@ -13,9 +13,8 @@
|
||||
//!
|
||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.130")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.172")]
|
||||
#![allow(unknown_lints, bare_trait_objects)]
|
||||
#![deny(clippy::all, clippy::pedantic)]
|
||||
// Ignored clippy lints
|
||||
#![allow(
|
||||
// clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7054
|
||||
@@ -23,6 +22,7 @@
|
||||
clippy::cognitive_complexity,
|
||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/7575
|
||||
clippy::collapsible_match,
|
||||
clippy::derive_partial_eq_without_eq,
|
||||
clippy::enum_variant_names,
|
||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6797
|
||||
clippy::manual_map,
|
||||
@@ -43,7 +43,8 @@
|
||||
clippy::enum_glob_use,
|
||||
clippy::indexing_slicing,
|
||||
clippy::items_after_statements,
|
||||
clippy::let_underscore_drop,
|
||||
clippy::let_underscore_untyped,
|
||||
clippy::manual_assert,
|
||||
clippy::map_err_ignore,
|
||||
clippy::match_same_arms,
|
||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6984
|
||||
@@ -60,18 +61,25 @@
|
||||
clippy::use_self,
|
||||
clippy::wildcard_imports
|
||||
)]
|
||||
#![cfg_attr(all(test, exhaustive), feature(non_exhaustive_omitted_patterns_lint))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
#[macro_use]
|
||||
extern crate syn;
|
||||
|
||||
#[cfg(not(precompiled))]
|
||||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
|
||||
#[cfg(precompiled)]
|
||||
extern crate proc_macro2 as proc_macro;
|
||||
|
||||
mod internals;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
#[cfg(precompiled)]
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use syn::DeriveInput;
|
||||
|
||||
#[macro_use]
|
||||
@@ -83,25 +91,34 @@ mod de;
|
||||
mod dummy;
|
||||
mod pretend;
|
||||
mod ser;
|
||||
mod this;
|
||||
mod try;
|
||||
|
||||
#[proc_macro_derive(Serialize, attributes(serde))]
|
||||
#[cfg(precompiled)]
|
||||
macro_rules! parse_macro_input {
|
||||
($tokenstream:ident as $ty:ty) => {
|
||||
match syn::parse2::<$ty>($tokenstream) {
|
||||
Ok(data) => data,
|
||||
Err(err) => return err.to_compile_error(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(precompiled)]
|
||||
pub static DESERIALIZE_IN_PLACE: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
#[cfg_attr(not(precompiled), proc_macro_derive(Serialize, attributes(serde)))]
|
||||
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
||||
let mut input = parse_macro_input!(input as DeriveInput);
|
||||
ser::expand_derive_serialize(&mut input)
|
||||
.unwrap_or_else(to_compile_errors)
|
||||
.unwrap_or_else(syn::Error::into_compile_error)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(Deserialize, attributes(serde))]
|
||||
#[cfg_attr(not(precompiled), proc_macro_derive(Deserialize, attributes(serde)))]
|
||||
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
||||
let mut input = parse_macro_input!(input as DeriveInput);
|
||||
de::expand_derive_deserialize(&mut input)
|
||||
.unwrap_or_else(to_compile_errors)
|
||||
.unwrap_or_else(syn::Error::into_compile_error)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn to_compile_errors(errors: Vec<syn::Error>) -> proc_macro2::TokenStream {
|
||||
let compile_errors = errors.iter().map(syn::Error::to_compile_error);
|
||||
quote!(#(#compile_errors)*)
|
||||
}
|
||||
|
||||
+14
-27
@@ -65,11 +65,13 @@ pub fn pretend_used(cont: &Container, is_packed: bool) -> TokenStream {
|
||||
fn pretend_fields_used(cont: &Container, is_packed: bool) -> TokenStream {
|
||||
match &cont.data {
|
||||
Data::Enum(variants) => pretend_fields_used_enum(cont, variants),
|
||||
Data::Struct(Style::Struct, fields) => if is_packed {
|
||||
pretend_fields_used_struct_packed(cont, fields)
|
||||
} else {
|
||||
pretend_fields_used_struct(cont, fields)
|
||||
},
|
||||
Data::Struct(Style::Struct, fields) => {
|
||||
if is_packed {
|
||||
pretend_fields_used_struct_packed(cont, fields)
|
||||
} else {
|
||||
pretend_fields_used_struct(cont, fields)
|
||||
}
|
||||
}
|
||||
Data::Struct(_, _) => quote!(),
|
||||
}
|
||||
}
|
||||
@@ -95,29 +97,14 @@ fn pretend_fields_used_struct_packed(cont: &Container, fields: &[Field]) -> Toke
|
||||
|
||||
let members = fields.iter().map(|field| &field.member).collect::<Vec<_>>();
|
||||
|
||||
#[cfg(ptr_addr_of)]
|
||||
{
|
||||
quote! {
|
||||
match _serde::__private::None::<&#type_ident #ty_generics> {
|
||||
_serde::__private::Some(__v @ #type_ident { #(#members: _),* }) => {
|
||||
#(
|
||||
let _ = _serde::__private::ptr::addr_of!(__v.#members);
|
||||
)*
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(ptr_addr_of))]
|
||||
{
|
||||
let placeholders = (0usize..).map(|i| format_ident!("__v{}", i));
|
||||
|
||||
quote! {
|
||||
match _serde::__private::None::<#type_ident #ty_generics> {
|
||||
_serde::__private::Some(#type_ident { #(#members: #placeholders),* }) => {}
|
||||
_ => {}
|
||||
quote! {
|
||||
match _serde::__private::None::<&#type_ident #ty_generics> {
|
||||
_serde::__private::Some(__v @ #type_ident { #(#members: _),* }) => {
|
||||
#(
|
||||
let _ = _serde::__private::ptr::addr_of!(__v.#members);
|
||||
)*
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+43
-40
@@ -8,10 +8,9 @@ use fragment::{Fragment, Match, Stmts};
|
||||
use internals::ast::{Container, Data, Field, Style, Variant};
|
||||
use internals::{attr, replace_receiver, Ctxt, Derive};
|
||||
use pretend;
|
||||
use this;
|
||||
|
||||
pub fn expand_derive_serialize(
|
||||
input: &mut syn::DeriveInput,
|
||||
) -> Result<TokenStream, Vec<syn::Error>> {
|
||||
pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
|
||||
replace_receiver(input);
|
||||
|
||||
let ctxt = Ctxt::new();
|
||||
@@ -58,8 +57,6 @@ pub fn expand_derive_serialize(
|
||||
|
||||
Ok(dummy::wrap_in_const(
|
||||
cont.attrs.custom_serde_path(),
|
||||
"SERIALIZE",
|
||||
ident,
|
||||
impl_block,
|
||||
))
|
||||
}
|
||||
@@ -82,9 +79,13 @@ struct Parameters {
|
||||
self_var: Ident,
|
||||
|
||||
/// Path to the type the impl is for. Either a single `Ident` for local
|
||||
/// types or `some::remote::Ident` for remote types. Does not include
|
||||
/// generic parameters.
|
||||
this: syn::Path,
|
||||
/// types (does not include generic parameters) or `some::remote::Path` for
|
||||
/// remote types.
|
||||
this_type: syn::Path,
|
||||
|
||||
/// Same as `this_type` but using `::<T>` for generic parameters for use in
|
||||
/// expression position.
|
||||
this_value: syn::Path,
|
||||
|
||||
/// Generics including any explicit and inferred bounds for the impl.
|
||||
generics: syn::Generics,
|
||||
@@ -105,18 +106,15 @@ impl Parameters {
|
||||
Ident::new("self", Span::call_site())
|
||||
};
|
||||
|
||||
let this = match cont.attrs.remote() {
|
||||
Some(remote) => remote.clone(),
|
||||
None => cont.ident.clone().into(),
|
||||
};
|
||||
|
||||
let this_type = this::this_type(cont);
|
||||
let this_value = this::this_value(cont);
|
||||
let is_packed = cont.attrs.is_packed();
|
||||
|
||||
let generics = build_generics(cont);
|
||||
|
||||
Parameters {
|
||||
self_var,
|
||||
this,
|
||||
this_type,
|
||||
this_value,
|
||||
generics,
|
||||
is_remote,
|
||||
is_packed,
|
||||
@@ -126,7 +124,7 @@ impl Parameters {
|
||||
/// Type name to use in error messages and `&'static str` arguments to
|
||||
/// various Serializer methods.
|
||||
fn type_name(&self) -> String {
|
||||
self.this.segments.last().unwrap().ident.to_string()
|
||||
self.this_type.segments.last().unwrap().ident.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,7 +425,7 @@ fn serialize_variant(
|
||||
variant_index: u32,
|
||||
cattrs: &attr::Container,
|
||||
) -> TokenStream {
|
||||
let this = ¶ms.this;
|
||||
let this_value = ¶ms.this_value;
|
||||
let variant_ident = &variant.ident;
|
||||
|
||||
if variant.attrs.skip_serializing() {
|
||||
@@ -445,47 +443,49 @@ fn serialize_variant(
|
||||
Style::Struct => quote!({ .. }),
|
||||
};
|
||||
quote! {
|
||||
#this::#variant_ident #fields_pat => #skipped_err,
|
||||
#this_value::#variant_ident #fields_pat => #skipped_err,
|
||||
}
|
||||
} else {
|
||||
// variant wasn't skipped
|
||||
let case = match variant.style {
|
||||
Style::Unit => {
|
||||
quote! {
|
||||
#this::#variant_ident
|
||||
#this_value::#variant_ident
|
||||
}
|
||||
}
|
||||
Style::Newtype => {
|
||||
quote! {
|
||||
#this::#variant_ident(ref __field0)
|
||||
#this_value::#variant_ident(ref __field0)
|
||||
}
|
||||
}
|
||||
Style::Tuple => {
|
||||
let field_names = (0..variant.fields.len())
|
||||
.map(|i| Ident::new(&format!("__field{}", i), Span::call_site()));
|
||||
quote! {
|
||||
#this::#variant_ident(#(ref #field_names),*)
|
||||
#this_value::#variant_ident(#(ref #field_names),*)
|
||||
}
|
||||
}
|
||||
Style::Struct => {
|
||||
let members = variant.fields.iter().map(|f| &f.member);
|
||||
quote! {
|
||||
#this::#variant_ident { #(ref #members),* }
|
||||
#this_value::#variant_ident { #(ref #members),* }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let body = Match(match cattrs.tag() {
|
||||
attr::TagType::External => {
|
||||
let body = Match(match (cattrs.tag(), variant.attrs.untagged()) {
|
||||
(attr::TagType::External, false) => {
|
||||
serialize_externally_tagged_variant(params, variant, variant_index, cattrs)
|
||||
}
|
||||
attr::TagType::Internal { tag } => {
|
||||
(attr::TagType::Internal { tag }, false) => {
|
||||
serialize_internally_tagged_variant(params, variant, cattrs, tag)
|
||||
}
|
||||
attr::TagType::Adjacent { tag, content } => {
|
||||
(attr::TagType::Adjacent { tag, content }, false) => {
|
||||
serialize_adjacently_tagged_variant(params, variant, cattrs, tag, content)
|
||||
}
|
||||
attr::TagType::None => serialize_untagged_variant(params, variant, cattrs),
|
||||
(attr::TagType::None, _) | (_, true) => {
|
||||
serialize_untagged_variant(params, variant, cattrs)
|
||||
}
|
||||
});
|
||||
|
||||
quote! {
|
||||
@@ -640,7 +640,7 @@ fn serialize_adjacently_tagged_variant(
|
||||
tag: &str,
|
||||
content: &str,
|
||||
) -> Fragment {
|
||||
let this = ¶ms.this;
|
||||
let this_type = ¶ms.this_type;
|
||||
let type_name = cattrs.name().serialize_name();
|
||||
let variant_name = variant.attrs.name().serialize_name();
|
||||
|
||||
@@ -717,9 +717,10 @@ fn serialize_adjacently_tagged_variant(
|
||||
let (wrapper_impl_generics, wrapper_ty_generics, _) = wrapper_generics.split_for_impl();
|
||||
|
||||
quote_block! {
|
||||
#[doc(hidden)]
|
||||
struct __AdjacentlyTagged #wrapper_generics #where_clause {
|
||||
data: (#(&'__a #fields_ty,)*),
|
||||
phantom: _serde::__private::PhantomData<#this #ty_generics>,
|
||||
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
|
||||
}
|
||||
|
||||
impl #wrapper_impl_generics _serde::Serialize for __AdjacentlyTagged #wrapper_ty_generics #where_clause {
|
||||
@@ -741,7 +742,7 @@ fn serialize_adjacently_tagged_variant(
|
||||
try!(_serde::ser::SerializeStruct::serialize_field(
|
||||
&mut __struct, #content, &__AdjacentlyTagged {
|
||||
data: (#(#fields_ident,)*),
|
||||
phantom: _serde::__private::PhantomData::<#this #ty_generics>,
|
||||
phantom: _serde::__private::PhantomData::<#this_type #ty_generics>,
|
||||
}));
|
||||
_serde::ser::SerializeStruct::end(__struct)
|
||||
}
|
||||
@@ -866,8 +867,8 @@ enum StructVariant<'a> {
|
||||
Untagged,
|
||||
}
|
||||
|
||||
fn serialize_struct_variant<'a>(
|
||||
context: StructVariant<'a>,
|
||||
fn serialize_struct_variant(
|
||||
context: StructVariant,
|
||||
params: &Parameters,
|
||||
fields: &[Field],
|
||||
name: &str,
|
||||
@@ -950,8 +951,8 @@ fn serialize_struct_variant<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_struct_variant_with_flatten<'a>(
|
||||
context: StructVariant<'a>,
|
||||
fn serialize_struct_variant_with_flatten(
|
||||
context: StructVariant,
|
||||
params: &Parameters,
|
||||
fields: &[Field],
|
||||
name: &str,
|
||||
@@ -971,7 +972,7 @@ fn serialize_struct_variant_with_flatten<'a>(
|
||||
variant_index,
|
||||
variant_name,
|
||||
} => {
|
||||
let this = ¶ms.this;
|
||||
let this_type = ¶ms.this_type;
|
||||
let fields_ty = fields.iter().map(|f| &f.ty);
|
||||
let members = &fields.iter().map(|f| &f.member).collect::<Vec<_>>();
|
||||
|
||||
@@ -980,9 +981,10 @@ fn serialize_struct_variant_with_flatten<'a>(
|
||||
let (wrapper_impl_generics, wrapper_ty_generics, _) = wrapper_generics.split_for_impl();
|
||||
|
||||
quote_block! {
|
||||
#[doc(hidden)]
|
||||
struct __EnumFlatten #wrapper_generics #where_clause {
|
||||
data: (#(&'__a #fields_ty,)*),
|
||||
phantom: _serde::__private::PhantomData<#this #ty_generics>,
|
||||
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
|
||||
}
|
||||
|
||||
impl #wrapper_impl_generics _serde::Serialize for __EnumFlatten #wrapper_ty_generics #where_clause {
|
||||
@@ -1006,7 +1008,7 @@ fn serialize_struct_variant_with_flatten<'a>(
|
||||
#variant_name,
|
||||
&__EnumFlatten {
|
||||
data: (#(#members,)*),
|
||||
phantom: _serde::__private::PhantomData::<#this #ty_generics>,
|
||||
phantom: _serde::__private::PhantomData::<#this_type #ty_generics>,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1192,7 +1194,7 @@ fn wrap_serialize_with(
|
||||
field_tys: &[&syn::Type],
|
||||
field_exprs: &[TokenStream],
|
||||
) -> TokenStream {
|
||||
let this = ¶ms.this;
|
||||
let this_type = ¶ms.this_type;
|
||||
let (_, ty_generics, where_clause) = params.generics.split_for_impl();
|
||||
|
||||
let wrapper_generics = if field_exprs.is_empty() {
|
||||
@@ -1210,9 +1212,10 @@ fn wrap_serialize_with(
|
||||
});
|
||||
|
||||
quote!({
|
||||
#[doc(hidden)]
|
||||
struct __SerializeWith #wrapper_impl_generics #where_clause {
|
||||
values: (#(&'__a #field_tys, )*),
|
||||
phantom: _serde::__private::PhantomData<#this #ty_generics>,
|
||||
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
|
||||
}
|
||||
|
||||
impl #wrapper_impl_generics _serde::Serialize for __SerializeWith #wrapper_ty_generics #where_clause {
|
||||
@@ -1226,7 +1229,7 @@ fn wrap_serialize_with(
|
||||
|
||||
&__SerializeWith {
|
||||
values: (#(#field_exprs, )*),
|
||||
phantom: _serde::__private::PhantomData::<#this #ty_generics>,
|
||||
phantom: _serde::__private::PhantomData::<#this_type #ty_generics>,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
use internals::ast::Container;
|
||||
use syn::{Path, PathArguments, Token};
|
||||
|
||||
pub fn this_type(cont: &Container) -> Path {
|
||||
if let Some(remote) = cont.attrs.remote() {
|
||||
let mut this = remote.clone();
|
||||
for segment in &mut this.segments {
|
||||
if let PathArguments::AngleBracketed(arguments) = &mut segment.arguments {
|
||||
arguments.colon2_token = None;
|
||||
}
|
||||
}
|
||||
this
|
||||
} else {
|
||||
Path::from(cont.ident.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn this_value(cont: &Container) -> Path {
|
||||
if let Some(remote) = cont.attrs.remote() {
|
||||
let mut this = remote.clone();
|
||||
for segment in &mut this.segments {
|
||||
if let PathArguments::AngleBracketed(arguments) = &mut segment.arguments {
|
||||
if arguments.colon2_token.is_none() {
|
||||
arguments.colon2_token = Some(Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
this
|
||||
} else {
|
||||
Path::from(cont.ident.clone())
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
[package]
|
||||
name = "serde_derive_internals"
|
||||
version = "0.26.0" # remember to update html_root_url
|
||||
version = "0.28.0" # remember to update html_root_url
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "AST representation used by Serde derive macros. Unstable."
|
||||
homepage = "https://serde.rs"
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
documentation = "https://docs.rs/serde_derive_internals"
|
||||
exclude = ["build.rs"]
|
||||
homepage = "https://serde.rs"
|
||||
keywords = ["serde", "serialization"]
|
||||
include = ["lib.rs", "src/**/*.rs", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
rust-version = "1.56"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
@@ -16,7 +17,7 @@ path = "lib.rs"
|
||||
[dependencies]
|
||||
proc-macro2 = "1.0"
|
||||
quote = "1.0"
|
||||
syn = { version = "1.0.60", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] }
|
||||
syn = { version = "2.0.25", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rerun-if-changed=src/mod.rs");
|
||||
|
||||
// Sometimes on Windows the git checkout does not correctly wire up the
|
||||
// symlink from serde_derive_internals/src to serde_derive/src/internals.
|
||||
// When this happens we'll just build based on relative paths within the git
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.26.0")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.28.0")]
|
||||
#![allow(unknown_lints, bare_trait_objects)]
|
||||
#![deny(clippy::all, clippy::pedantic)]
|
||||
// Ignored clippy lints
|
||||
#![allow(
|
||||
clippy::cognitive_complexity,
|
||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/7575
|
||||
clippy::collapsible_match,
|
||||
clippy::derive_partial_eq_without_eq,
|
||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6797
|
||||
clippy::manual_map,
|
||||
clippy::missing_panics_doc,
|
||||
@@ -22,7 +22,8 @@
|
||||
clippy::doc_markdown,
|
||||
clippy::enum_glob_use,
|
||||
clippy::items_after_statements,
|
||||
clippy::let_underscore_drop,
|
||||
clippy::let_underscore_untyped,
|
||||
clippy::manual_assert,
|
||||
clippy::match_same_arms,
|
||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6984
|
||||
clippy::match_wildcard_for_single_variants,
|
||||
@@ -30,6 +31,7 @@
|
||||
clippy::module_name_repetitions,
|
||||
clippy::must_use_candidate,
|
||||
clippy::similar_names,
|
||||
clippy::single_match_else,
|
||||
clippy::struct_excessive_bools,
|
||||
clippy::too_many_lines,
|
||||
clippy::unused_self,
|
||||
|
||||
+13
-8
@@ -1,22 +1,27 @@
|
||||
[package]
|
||||
name = "serde_test"
|
||||
version = "1.0.130" # remember to update html_root_url
|
||||
version = "1.0.172" # remember to update html_root_url
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
build = "build.rs"
|
||||
categories = ["development-tools::testing"]
|
||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||
documentation = "https://docs.rs/serde_test"
|
||||
homepage = "https://serde.rs"
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
documentation = "https://docs.serde.rs/serde_test/"
|
||||
keywords = ["serde", "serialization"]
|
||||
keywords = ["serde", "serialization", "testing", "dev-dependencies"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
readme = "crates-io.md"
|
||||
include = ["src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||
repository = "https://github.com/serde-rs/serde"
|
||||
rust-version = "1.19"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.60", path = "../serde" }
|
||||
|
||||
[dev-dependencies]
|
||||
serde = { version = "1.0", path = "../serde" }
|
||||
serde_derive = { version = "1.0", path = "../serde_derive" }
|
||||
serde = { version = "1", path = "../serde", features = ["rc"] }
|
||||
serde_derive = { version = "1", path = "../serde_derive" }
|
||||
|
||||
[lib]
|
||||
doc-scrape-examples = false
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
+27
-7
@@ -1,11 +1,13 @@
|
||||
use std::env;
|
||||
use std::process::Command;
|
||||
use std::str;
|
||||
use std::str::{self, FromStr};
|
||||
|
||||
// The rustc-cfg strings below are *not* public API. Please let us know by
|
||||
// opening a GitHub issue if your build environment requires some way to enable
|
||||
// these cfgs other than by executing our build script.
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
||||
let minor = match rustc_minor_version() {
|
||||
Some(minor) => minor,
|
||||
None => return,
|
||||
@@ -13,18 +15,36 @@ fn main() {
|
||||
|
||||
// #[track_caller] stabilized in Rust 1.46:
|
||||
// https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html#track_caller
|
||||
if minor >= 46 {
|
||||
println!("cargo:rustc-cfg=track_caller");
|
||||
if minor < 46 {
|
||||
println!("cargo:rustc-cfg=no_track_caller");
|
||||
}
|
||||
}
|
||||
|
||||
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 rustc = match env::var_os("RUSTC") {
|
||||
Some(rustc) => rustc,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
let output = match Command::new(rustc).arg("--version").output() {
|
||||
Ok(output) => output,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let version = match str::from_utf8(&output.stdout) {
|
||||
Ok(version) => version,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let mut pieces = version.split('.');
|
||||
if pieces.next() != Some("rustc 1") {
|
||||
return None;
|
||||
}
|
||||
pieces.next()?.parse().ok()
|
||||
|
||||
let next = match pieces.next() {
|
||||
Some(next) => next,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
u32::from_str(next).ok()
|
||||
}
|
||||
|
||||
+61
-47
@@ -8,8 +8,8 @@ use std::fmt::Debug;
|
||||
|
||||
/// Runs both `assert_ser_tokens` and `assert_de_tokens`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
@@ -19,16 +19,19 @@ use std::fmt::Debug;
|
||||
/// }
|
||||
///
|
||||
/// let s = S { a: 0, b: 0 };
|
||||
/// assert_tokens(&s, &[
|
||||
/// Token::Struct { name: "S", len: 2 },
|
||||
/// Token::Str("a"),
|
||||
/// Token::U8(0),
|
||||
/// Token::Str("b"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &s,
|
||||
/// &[
|
||||
/// Token::Struct { name: "S", len: 2 },
|
||||
/// Token::Str("a"),
|
||||
/// Token::U8(0),
|
||||
/// Token::Str("b"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// ```
|
||||
#[cfg_attr(track_caller, track_caller)]
|
||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
||||
pub fn assert_tokens<'de, T>(value: &T, tokens: &'de [Token])
|
||||
where
|
||||
T: Serialize + Deserialize<'de> + PartialEq + Debug,
|
||||
@@ -39,8 +42,8 @@ where
|
||||
|
||||
/// Asserts that `value` serializes to the given `tokens`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_ser_tokens, Token};
|
||||
/// #
|
||||
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
@@ -50,17 +53,20 @@ where
|
||||
/// }
|
||||
///
|
||||
/// let s = S { a: 0, b: 0 };
|
||||
/// assert_ser_tokens(&s, &[
|
||||
/// Token::Struct { name: "S", len: 2 },
|
||||
/// Token::Str("a"),
|
||||
/// Token::U8(0),
|
||||
/// Token::Str("b"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructEnd,
|
||||
/// ]);
|
||||
/// assert_ser_tokens(
|
||||
/// &s,
|
||||
/// &[
|
||||
/// Token::Struct { name: "S", len: 2 },
|
||||
/// Token::Str("a"),
|
||||
/// Token::U8(0),
|
||||
/// Token::Str("b"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// ```
|
||||
#[cfg_attr(track_caller, track_caller)]
|
||||
pub fn assert_ser_tokens<T>(value: &T, tokens: &[Token])
|
||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
||||
pub fn assert_ser_tokens<T: ?Sized>(value: &T, tokens: &[Token])
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -78,23 +84,24 @@ where
|
||||
/// Asserts that `value` serializes to the given `tokens`, and then yields
|
||||
/// `error`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde_derive::Serialize;
|
||||
/// use serde_test::{assert_ser_tokens_error, Token};
|
||||
/// use std::sync::{Arc, Mutex};
|
||||
/// use std::thread;
|
||||
///
|
||||
/// use serde::Serialize;
|
||||
/// use serde_test::{assert_ser_tokens_error, Token};
|
||||
///
|
||||
/// #[derive(Serialize)]
|
||||
/// struct Example {
|
||||
/// lock: Arc<Mutex<u32>>,
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let example = Example { lock: Arc::new(Mutex::new(0)) };
|
||||
/// let example = Example {
|
||||
/// lock: Arc::new(Mutex::new(0)),
|
||||
/// };
|
||||
/// let lock = example.lock.clone();
|
||||
///
|
||||
/// let _ = thread::spawn(move || {
|
||||
/// let thread = thread::spawn(move || {
|
||||
/// // This thread will acquire the mutex first, unwrapping the result
|
||||
/// // of `lock` because the lock has not been poisoned.
|
||||
/// let _guard = lock.lock().unwrap();
|
||||
@@ -102,18 +109,22 @@ where
|
||||
/// // This panic while holding the lock (`_guard` is in scope) will
|
||||
/// // poison the mutex.
|
||||
/// panic!()
|
||||
/// }).join();
|
||||
/// });
|
||||
/// thread.join();
|
||||
///
|
||||
/// let expected = &[
|
||||
/// Token::Struct { name: "Example", len: 1 },
|
||||
/// Token::Struct {
|
||||
/// name: "Example",
|
||||
/// len: 1,
|
||||
/// },
|
||||
/// Token::Str("lock"),
|
||||
/// ];
|
||||
/// let error = "lock poison error while serializing";
|
||||
/// assert_ser_tokens_error(&example, expected, error);
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg_attr(track_caller, track_caller)]
|
||||
pub fn assert_ser_tokens_error<T>(value: &T, tokens: &[Token], error: &str)
|
||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
||||
pub fn assert_ser_tokens_error<T: ?Sized>(value: &T, tokens: &[Token], error: &str)
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -130,8 +141,8 @@ where
|
||||
|
||||
/// Asserts that the given `tokens` deserialize into `value`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_de_tokens, Token};
|
||||
/// #
|
||||
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
@@ -141,16 +152,19 @@ where
|
||||
/// }
|
||||
///
|
||||
/// let s = S { a: 0, b: 0 };
|
||||
/// assert_de_tokens(&s, &[
|
||||
/// Token::Struct { name: "S", len: 2 },
|
||||
/// Token::Str("a"),
|
||||
/// Token::U8(0),
|
||||
/// Token::Str("b"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructEnd,
|
||||
/// ]);
|
||||
/// assert_de_tokens(
|
||||
/// &s,
|
||||
/// &[
|
||||
/// Token::Struct { name: "S", len: 2 },
|
||||
/// Token::Str("a"),
|
||||
/// Token::U8(0),
|
||||
/// Token::Str("b"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// ```
|
||||
#[cfg_attr(track_caller, track_caller)]
|
||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
||||
pub fn assert_de_tokens<'de, T>(value: &T, tokens: &'de [Token])
|
||||
where
|
||||
T: Deserialize<'de> + PartialEq + Debug,
|
||||
@@ -184,8 +198,8 @@ where
|
||||
|
||||
/// Asserts that the given `tokens` yield `error` when deserializing.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_de_tokens_error, Token};
|
||||
/// #
|
||||
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
@@ -203,7 +217,7 @@ where
|
||||
/// "unknown field `x`, expected `a` or `b`",
|
||||
/// );
|
||||
/// ```
|
||||
#[cfg_attr(track_caller, track_caller)]
|
||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
||||
pub fn assert_de_tokens_error<'de, T>(tokens: &'de [Token], error: &str)
|
||||
where
|
||||
T: Deserialize<'de>,
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct Compact<T: ?Sized>(T);
|
||||
/// Trait to determine whether a value is represented in human-readable or
|
||||
/// compact form.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
/// use serde_test::{assert_tokens, Configure, Token};
|
||||
///
|
||||
|
||||
+83
-95
@@ -12,32 +12,29 @@ pub struct Deserializer<'de> {
|
||||
tokens: &'de [Token],
|
||||
}
|
||||
|
||||
macro_rules! assert_next_token {
|
||||
($de:expr, $expected:expr) => {
|
||||
match $de.next_token_opt() {
|
||||
Some(token) if token == $expected => {}
|
||||
Some(other) => panic!(
|
||||
"expected Token::{} but deserialization wants Token::{}",
|
||||
other, $expected
|
||||
),
|
||||
None => panic!(
|
||||
"end of tokens but deserialization wants Token::{}",
|
||||
$expected
|
||||
),
|
||||
}
|
||||
};
|
||||
fn assert_next_token(de: &mut Deserializer, expected: Token) -> Result<(), Error> {
|
||||
match de.next_token_opt() {
|
||||
Some(token) if token == expected => Ok(()),
|
||||
Some(other) => Err(de::Error::custom(format!(
|
||||
"expected Token::{} but deserialization wants Token::{}",
|
||||
other, expected,
|
||||
))),
|
||||
None => Err(de::Error::custom(format!(
|
||||
"end of tokens but deserialization wants Token::{}",
|
||||
expected,
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! unexpected {
|
||||
($token:expr) => {
|
||||
panic!("deserialization did not expect this token: {}", $token)
|
||||
};
|
||||
fn unexpected(token: Token) -> Error {
|
||||
de::Error::custom(format!(
|
||||
"deserialization did not expect this token: {}",
|
||||
token,
|
||||
))
|
||||
}
|
||||
|
||||
macro_rules! end_of_tokens {
|
||||
() => {
|
||||
panic!("ran out of tokens to deserialize")
|
||||
};
|
||||
fn end_of_tokens() -> Error {
|
||||
de::Error::custom("ran out of tokens to deserialize")
|
||||
}
|
||||
|
||||
impl<'de> Deserializer<'de> {
|
||||
@@ -49,11 +46,8 @@ impl<'de> Deserializer<'de> {
|
||||
self.tokens.first().cloned()
|
||||
}
|
||||
|
||||
fn peek_token(&self) -> Token {
|
||||
match self.peek_token_opt() {
|
||||
Some(token) => token,
|
||||
None => end_of_tokens!(),
|
||||
}
|
||||
fn peek_token(&self) -> Result<Token, Error> {
|
||||
self.peek_token_opt().ok_or_else(end_of_tokens)
|
||||
}
|
||||
|
||||
pub fn next_token_opt(&mut self) -> Option<Token> {
|
||||
@@ -66,14 +60,10 @@ impl<'de> Deserializer<'de> {
|
||||
}
|
||||
}
|
||||
|
||||
fn next_token(&mut self) -> Token {
|
||||
match self.tokens.split_first() {
|
||||
Some((&first, rest)) => {
|
||||
self.tokens = rest;
|
||||
first
|
||||
}
|
||||
None => end_of_tokens!(),
|
||||
}
|
||||
fn next_token(&mut self) -> Result<Token, Error> {
|
||||
let (&first, rest) = self.tokens.split_first().ok_or_else(end_of_tokens)?;
|
||||
self.tokens = rest;
|
||||
Ok(first)
|
||||
}
|
||||
|
||||
pub fn remaining(&self) -> usize {
|
||||
@@ -94,7 +84,7 @@ impl<'de> Deserializer<'de> {
|
||||
len: len,
|
||||
end: end,
|
||||
})?;
|
||||
assert_next_token!(self, end);
|
||||
assert_next_token(self, end)?;
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
@@ -112,7 +102,7 @@ impl<'de> Deserializer<'de> {
|
||||
len: len,
|
||||
end: end,
|
||||
})?;
|
||||
assert_next_token!(self, end);
|
||||
assert_next_token(self, end)?;
|
||||
Ok(value)
|
||||
}
|
||||
}
|
||||
@@ -129,7 +119,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
let token = self.next_token();
|
||||
let token = self.next_token()?;
|
||||
match token {
|
||||
Token::Bool(v) => visitor.visit_bool(v),
|
||||
Token::I8(v) => visitor.visit_i8(v),
|
||||
@@ -161,50 +151,50 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
Token::Map { len } => self.visit_map(len, Token::MapEnd, visitor),
|
||||
Token::Struct { len, .. } => self.visit_map(Some(len), Token::StructEnd, visitor),
|
||||
Token::Enum { .. } => {
|
||||
let variant = self.next_token();
|
||||
let next = self.peek_token();
|
||||
let variant = self.next_token()?;
|
||||
let next = self.peek_token()?;
|
||||
match (variant, next) {
|
||||
(Token::Str(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_str(variant)
|
||||
}
|
||||
(Token::BorrowedStr(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_borrowed_str(variant)
|
||||
}
|
||||
(Token::String(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_string(variant.to_string())
|
||||
}
|
||||
(Token::Bytes(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_bytes(variant)
|
||||
}
|
||||
(Token::BorrowedBytes(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_borrowed_bytes(variant)
|
||||
}
|
||||
(Token::ByteBuf(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_byte_buf(variant.to_vec())
|
||||
}
|
||||
(Token::U8(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_u8(variant)
|
||||
}
|
||||
(Token::U16(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_u16(variant)
|
||||
}
|
||||
(Token::U32(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_u32(variant)
|
||||
}
|
||||
(Token::U64(variant), Token::Unit) => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_u64(variant)
|
||||
}
|
||||
(variant, Token::Unit) => unexpected!(variant),
|
||||
(variant, Token::Unit) => Err(unexpected(variant)),
|
||||
(variant, _) => {
|
||||
visitor.visit_map(EnumMapVisitor::new(self, variant, EnumFormat::Any))
|
||||
}
|
||||
@@ -232,9 +222,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
| Token::MapEnd
|
||||
| Token::StructEnd
|
||||
| Token::TupleVariantEnd
|
||||
| Token::StructVariantEnd => {
|
||||
unexpected!(token);
|
||||
}
|
||||
| Token::StructVariantEnd => Err(unexpected(token)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,13 +230,13 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self.peek_token() {
|
||||
match self.peek_token()? {
|
||||
Token::Unit | Token::None => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_none()
|
||||
}
|
||||
Token::Some => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_some(self)
|
||||
}
|
||||
_ => self.deserialize_any(visitor),
|
||||
@@ -264,9 +252,9 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self.peek_token() {
|
||||
match self.peek_token()? {
|
||||
Token::Enum { name: n } if name == n => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
|
||||
visitor.visit_enum(DeserializerEnumVisitor { de: self })
|
||||
}
|
||||
@@ -286,9 +274,9 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self.peek_token() {
|
||||
match self.peek_token()? {
|
||||
Token::UnitStruct { .. } => {
|
||||
assert_next_token!(self, Token::UnitStruct { name: name });
|
||||
assert_next_token(self, Token::UnitStruct { name: name })?;
|
||||
visitor.visit_unit()
|
||||
}
|
||||
_ => self.deserialize_any(visitor),
|
||||
@@ -303,9 +291,9 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self.peek_token() {
|
||||
match self.peek_token()? {
|
||||
Token::NewtypeStruct { .. } => {
|
||||
assert_next_token!(self, Token::NewtypeStruct { name: name });
|
||||
assert_next_token(self, Token::NewtypeStruct { name: name })?;
|
||||
visitor.visit_newtype_struct(self)
|
||||
}
|
||||
_ => self.deserialize_any(visitor),
|
||||
@@ -316,21 +304,21 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self.peek_token() {
|
||||
match self.peek_token()? {
|
||||
Token::Unit | Token::UnitStruct { .. } => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_unit()
|
||||
}
|
||||
Token::Seq { .. } => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
self.visit_seq(Some(len), Token::SeqEnd, visitor)
|
||||
}
|
||||
Token::Tuple { .. } => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
self.visit_seq(Some(len), Token::TupleEnd, visitor)
|
||||
}
|
||||
Token::TupleStruct { .. } => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
self.visit_seq(Some(len), Token::TupleStructEnd, visitor)
|
||||
}
|
||||
_ => self.deserialize_any(visitor),
|
||||
@@ -346,25 +334,25 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self.peek_token() {
|
||||
match self.peek_token()? {
|
||||
Token::Unit => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
visitor.visit_unit()
|
||||
}
|
||||
Token::UnitStruct { .. } => {
|
||||
assert_next_token!(self, Token::UnitStruct { name: name });
|
||||
assert_next_token(self, Token::UnitStruct { name: name })?;
|
||||
visitor.visit_unit()
|
||||
}
|
||||
Token::Seq { .. } => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
self.visit_seq(Some(len), Token::SeqEnd, visitor)
|
||||
}
|
||||
Token::Tuple { .. } => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
self.visit_seq(Some(len), Token::TupleEnd, visitor)
|
||||
}
|
||||
Token::TupleStruct { len: n, .. } => {
|
||||
assert_next_token!(self, Token::TupleStruct { name: name, len: n });
|
||||
assert_next_token(self, Token::TupleStruct { name: name, len: n })?;
|
||||
self.visit_seq(Some(len), Token::TupleStructEnd, visitor)
|
||||
}
|
||||
_ => self.deserialize_any(visitor),
|
||||
@@ -380,13 +368,13 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self.peek_token() {
|
||||
match self.peek_token()? {
|
||||
Token::Struct { len: n, .. } => {
|
||||
assert_next_token!(self, Token::Struct { name: name, len: n });
|
||||
assert_next_token(self, Token::Struct { name: name, len: n })?;
|
||||
self.visit_map(Some(fields.len()), Token::StructEnd, visitor)
|
||||
}
|
||||
Token::Map { .. } => {
|
||||
self.next_token();
|
||||
self.next_token()?;
|
||||
self.visit_map(Some(fields.len()), Token::MapEnd, visitor)
|
||||
}
|
||||
_ => self.deserialize_any(visitor),
|
||||
@@ -476,7 +464,7 @@ impl<'de, 'a> EnumAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
|
||||
where
|
||||
V: DeserializeSeed<'de>,
|
||||
{
|
||||
match self.de.peek_token() {
|
||||
match self.de.peek_token()? {
|
||||
Token::UnitVariant { variant: v, .. }
|
||||
| Token::NewtypeVariant { variant: v, .. }
|
||||
| Token::TupleVariant { variant: v, .. }
|
||||
@@ -497,9 +485,9 @@ impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
|
||||
type Error = Error;
|
||||
|
||||
fn unit_variant(self) -> Result<(), Error> {
|
||||
match self.de.peek_token() {
|
||||
match self.de.peek_token()? {
|
||||
Token::UnitVariant { .. } => {
|
||||
self.de.next_token();
|
||||
self.de.next_token()?;
|
||||
Ok(())
|
||||
}
|
||||
_ => Deserialize::deserialize(self.de),
|
||||
@@ -510,9 +498,9 @@ impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
|
||||
where
|
||||
T: DeserializeSeed<'de>,
|
||||
{
|
||||
match self.de.peek_token() {
|
||||
match self.de.peek_token()? {
|
||||
Token::NewtypeVariant { .. } => {
|
||||
self.de.next_token();
|
||||
self.de.next_token()?;
|
||||
seed.deserialize(self.de)
|
||||
}
|
||||
_ => seed.deserialize(self.de),
|
||||
@@ -523,26 +511,26 @@ impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self.de.peek_token() {
|
||||
match self.de.peek_token()? {
|
||||
Token::TupleVariant { len: enum_len, .. } => {
|
||||
let token = self.de.next_token();
|
||||
let token = self.de.next_token()?;
|
||||
|
||||
if len == enum_len {
|
||||
self.de
|
||||
.visit_seq(Some(len), Token::TupleVariantEnd, visitor)
|
||||
} else {
|
||||
unexpected!(token);
|
||||
Err(unexpected(token))
|
||||
}
|
||||
}
|
||||
Token::Seq {
|
||||
len: Some(enum_len),
|
||||
} => {
|
||||
let token = self.de.next_token();
|
||||
let token = self.de.next_token()?;
|
||||
|
||||
if len == enum_len {
|
||||
self.de.visit_seq(Some(len), Token::SeqEnd, visitor)
|
||||
} else {
|
||||
unexpected!(token);
|
||||
Err(unexpected(token))
|
||||
}
|
||||
}
|
||||
_ => de::Deserializer::deserialize_any(self.de, visitor),
|
||||
@@ -557,27 +545,27 @@ impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self.de.peek_token() {
|
||||
match self.de.peek_token()? {
|
||||
Token::StructVariant { len: enum_len, .. } => {
|
||||
let token = self.de.next_token();
|
||||
let token = self.de.next_token()?;
|
||||
|
||||
if fields.len() == enum_len {
|
||||
self.de
|
||||
.visit_map(Some(fields.len()), Token::StructVariantEnd, visitor)
|
||||
} else {
|
||||
unexpected!(token);
|
||||
Err(unexpected(token))
|
||||
}
|
||||
}
|
||||
Token::Map {
|
||||
len: Some(enum_len),
|
||||
} => {
|
||||
let token = self.de.next_token();
|
||||
let token = self.de.next_token()?;
|
||||
|
||||
if fields.len() == enum_len {
|
||||
self.de
|
||||
.visit_map(Some(fields.len()), Token::MapEnd, visitor)
|
||||
} else {
|
||||
unexpected!(token);
|
||||
Err(unexpected(token))
|
||||
}
|
||||
}
|
||||
_ => de::Deserializer::deserialize_any(self.de, visitor),
|
||||
@@ -622,7 +610,7 @@ impl<'de, 'a> MapAccess<'de> for EnumMapVisitor<'a, 'de> {
|
||||
.deserialize(BytesDeserializer { value: variant })
|
||||
.map(Some),
|
||||
Some(Token::U32(variant)) => seed.deserialize(variant.into_deserializer()).map(Some),
|
||||
Some(other) => unexpected!(other),
|
||||
Some(other) => Err(unexpected(other)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
@@ -641,7 +629,7 @@ impl<'de, 'a> MapAccess<'de> for EnumMapVisitor<'a, 'de> {
|
||||
};
|
||||
seed.deserialize(SeqAccessDeserializer::new(visitor))?
|
||||
};
|
||||
assert_next_token!(self.de, Token::TupleVariantEnd);
|
||||
assert_next_token(self.de, Token::TupleVariantEnd)?;
|
||||
Ok(value)
|
||||
}
|
||||
EnumFormat::Map => {
|
||||
@@ -653,7 +641,7 @@ impl<'de, 'a> MapAccess<'de> for EnumMapVisitor<'a, 'de> {
|
||||
};
|
||||
seed.deserialize(MapAccessDeserializer::new(visitor))?
|
||||
};
|
||||
assert_next_token!(self.de, Token::StructVariantEnd);
|
||||
assert_next_token(self.de, Token::StructVariantEnd)?;
|
||||
Ok(value)
|
||||
}
|
||||
EnumFormat::Any => seed.deserialize(&mut *self.de),
|
||||
|
||||
+29
-31
@@ -1,8 +1,8 @@
|
||||
//! This crate provides a convenient concise way to write unit tests for
|
||||
//! implementations of [`Serialize`] and [`Deserialize`].
|
||||
//!
|
||||
//! [`Serialize`]: https://docs.serde.rs/serde/ser/trait.Serialize.html
|
||||
//! [`Deserialize`]: https://docs.serde.rs/serde/de/trait.Deserialize.html
|
||||
//! [`Serialize`]: serde::ser::Serialize
|
||||
//! [`Deserialize`]: serde::de::Deserialize
|
||||
//!
|
||||
//! The `Serialize` impl for a value can be characterized by the sequence of
|
||||
//! [`Serializer`] calls that are made in the course of serializing the value,
|
||||
@@ -14,21 +14,17 @@
|
||||
//! test both directions. There are also functions to test expected failure
|
||||
//! conditions.
|
||||
//!
|
||||
//! [`Serializer`]: https://docs.serde.rs/serde/ser/trait.Serializer.html
|
||||
//! [`Token`]: https://docs.serde.rs/serde_test/enum.Token.html
|
||||
//! [`assert_ser_tokens`]: https://docs.serde.rs/serde_test/fn.assert_ser_tokens.html
|
||||
//! [`assert_de_tokens`]: https://docs.serde.rs/serde_test/fn.assert_de_tokens.html
|
||||
//! [`assert_tokens`]: https://docs.serde.rs/serde_test/fn.assert_tokens.html
|
||||
//! [`Serializer`]: serde::ser::Serializer
|
||||
//!
|
||||
//! Here is an example from the [`linked-hash-map`] crate.
|
||||
//!
|
||||
//! [`linked-hash-map`]: https://github.com/contain-rs/linked-hash-map
|
||||
//!
|
||||
//! ```edition2018
|
||||
//! ```edition2021
|
||||
//! # const IGNORE: &str = stringify! {
|
||||
//! use linked_hash_map::LinkedHashMap;
|
||||
//! # };
|
||||
//! use serde_test::{Token, assert_tokens};
|
||||
//! use serde_test::{assert_tokens, Token};
|
||||
//!
|
||||
//! # use std::fmt;
|
||||
//! # use std::marker::PhantomData;
|
||||
@@ -110,10 +106,13 @@
|
||||
//! fn test_ser_de_empty() {
|
||||
//! let map = LinkedHashMap::<char, u32>::new();
|
||||
//!
|
||||
//! assert_tokens(&map, &[
|
||||
//! Token::Map { len: Some(0) },
|
||||
//! Token::MapEnd,
|
||||
//! ]);
|
||||
//! assert_tokens(
|
||||
//! &map,
|
||||
//! &[
|
||||
//! Token::Map { len: Some(0) },
|
||||
//! Token::MapEnd,
|
||||
//! ],
|
||||
//! );
|
||||
//! }
|
||||
//!
|
||||
//! #[test]
|
||||
@@ -124,18 +123,19 @@
|
||||
//! map.insert('a', 10);
|
||||
//! map.insert('c', 30);
|
||||
//!
|
||||
//! assert_tokens(&map, &[
|
||||
//! Token::Map { len: Some(3) },
|
||||
//! Token::Char('b'),
|
||||
//! Token::I32(20),
|
||||
//!
|
||||
//! Token::Char('a'),
|
||||
//! Token::I32(10),
|
||||
//!
|
||||
//! Token::Char('c'),
|
||||
//! Token::I32(30),
|
||||
//! Token::MapEnd,
|
||||
//! ]);
|
||||
//! assert_tokens(
|
||||
//! &map,
|
||||
//! &[
|
||||
//! Token::Map { len: Some(3) },
|
||||
//! Token::Char('b'),
|
||||
//! Token::I32(20),
|
||||
//! Token::Char('a'),
|
||||
//! Token::I32(10),
|
||||
//! Token::Char('c'),
|
||||
//! Token::I32(30),
|
||||
//! Token::MapEnd,
|
||||
//! ],
|
||||
//! );
|
||||
//! }
|
||||
//! #
|
||||
//! # fn main() {
|
||||
@@ -144,9 +144,8 @@
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.130")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.172")]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||
// Ignored clippy lints
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp, needless_doctest_main))]
|
||||
// Ignored clippy_pedantic lints
|
||||
@@ -154,13 +153,16 @@
|
||||
feature = "cargo-clippy",
|
||||
allow(
|
||||
cloned_instead_of_copied,
|
||||
doc_link_with_quotes, // https://github.com/rust-lang/rust-clippy/issues/8961
|
||||
empty_line_after_outer_attr,
|
||||
manual_assert,
|
||||
missing_docs_in_private_items,
|
||||
missing_panics_doc,
|
||||
module_name_repetitions,
|
||||
must_use_candidate,
|
||||
redundant_field_names,
|
||||
too_many_lines,
|
||||
type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
|
||||
use_debug,
|
||||
use_self
|
||||
)
|
||||
@@ -184,7 +186,3 @@ pub use assert::{
|
||||
pub use token::Token;
|
||||
|
||||
pub use configure::{Compact, Configure, Readable};
|
||||
|
||||
// Not public API.
|
||||
#[doc(hidden)]
|
||||
pub use de::Deserializer;
|
||||
|
||||
@@ -63,14 +63,12 @@ macro_rules! assert_next_token {
|
||||
($ser:expr, $actual:expr, $pat:pat, $guard:expr) => {
|
||||
match $ser.next_token() {
|
||||
Some($pat) if $guard => {}
|
||||
Some(expected) => {
|
||||
panic!("expected Token::{} but serialized as {}",
|
||||
expected, $actual);
|
||||
}
|
||||
None => {
|
||||
panic!("expected end of tokens, but {} was serialized",
|
||||
$actual);
|
||||
}
|
||||
Some(expected) => return Err(ser::Error::custom(
|
||||
format!("expected Token::{} but serialized as {}", expected, $actual)
|
||||
)),
|
||||
None => return Err(ser::Error::custom(
|
||||
format!("expected end of tokens, but {} was serialized", $actual)
|
||||
)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+167
-125
@@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Display};
|
||||
pub enum Token {
|
||||
/// A serialized `bool`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&true, &[Token::Bool(true)]);
|
||||
@@ -13,7 +13,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `i8`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0i8, &[Token::I8(0)]);
|
||||
@@ -22,7 +22,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `i16`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0i16, &[Token::I16(0)]);
|
||||
@@ -31,7 +31,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `i32`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0i32, &[Token::I32(0)]);
|
||||
@@ -40,7 +40,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `i64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0i64, &[Token::I64(0)]);
|
||||
@@ -49,7 +49,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `u8`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0u8, &[Token::U8(0)]);
|
||||
@@ -58,7 +58,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `u16`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0u16, &[Token::U16(0)]);
|
||||
@@ -67,7 +67,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `u32`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0u32, &[Token::U32(0)]);
|
||||
@@ -76,7 +76,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `u64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0u64, &[Token::U64(0)]);
|
||||
@@ -85,7 +85,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `f32`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0f32, &[Token::F32(0.0)]);
|
||||
@@ -94,7 +94,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `f64`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&0f64, &[Token::F64(0.0)]);
|
||||
@@ -103,7 +103,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `char`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&'\n', &[Token::Char('\n')]);
|
||||
@@ -112,7 +112,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `str`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// let s = String::from("transient");
|
||||
@@ -122,7 +122,7 @@ pub enum Token {
|
||||
|
||||
/// A borrowed `str`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// let s: &str = "borrowed";
|
||||
@@ -132,7 +132,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `String`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// let s = String::from("owned");
|
||||
@@ -151,7 +151,7 @@ pub enum Token {
|
||||
|
||||
/// A serialized `Option<T>` containing none.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// let opt = None::<char>;
|
||||
@@ -163,20 +163,17 @@ pub enum Token {
|
||||
///
|
||||
/// The tokens of the value follow after this header.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// let opt = Some('c');
|
||||
/// assert_tokens(&opt, &[
|
||||
/// Token::Some,
|
||||
/// Token::Char('c'),
|
||||
/// ]);
|
||||
/// assert_tokens(&opt, &[Token::Some, Token::Char('c')]);
|
||||
/// ```
|
||||
Some,
|
||||
|
||||
/// A serialized `()`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// assert_tokens(&(), &[Token::Unit]);
|
||||
@@ -185,8 +182,8 @@ pub enum Token {
|
||||
|
||||
/// A serialized unit struct of the given name.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
@@ -200,8 +197,8 @@ pub enum Token {
|
||||
|
||||
/// A unit variant of an enum.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
@@ -211,7 +208,13 @@ pub enum Token {
|
||||
/// }
|
||||
///
|
||||
/// let a = E::A;
|
||||
/// assert_tokens(&a, &[Token::UnitVariant { name: "E", variant: "A" }]);
|
||||
/// assert_tokens(
|
||||
/// &a,
|
||||
/// &[Token::UnitVariant {
|
||||
/// name: "E",
|
||||
/// variant: "A",
|
||||
/// }],
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
UnitVariant {
|
||||
@@ -223,8 +226,8 @@ pub enum Token {
|
||||
///
|
||||
/// After this header is the value contained in the newtype struct.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
@@ -232,10 +235,10 @@ pub enum Token {
|
||||
/// struct N(String);
|
||||
///
|
||||
/// let n = N("newtype".to_owned());
|
||||
/// assert_tokens(&n, &[
|
||||
/// Token::NewtypeStruct { name: "N" },
|
||||
/// Token::String("newtype"),
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &n,
|
||||
/// &[Token::NewtypeStruct { name: "N" }, Token::String("newtype")],
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
NewtypeStruct { name: &'static str },
|
||||
@@ -244,8 +247,8 @@ pub enum Token {
|
||||
///
|
||||
/// After this header is the value contained in the newtype variant.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
@@ -255,10 +258,16 @@ pub enum Token {
|
||||
/// }
|
||||
///
|
||||
/// let b = E::B(0);
|
||||
/// assert_tokens(&b, &[
|
||||
/// Token::NewtypeVariant { name: "E", variant: "B" },
|
||||
/// Token::U8(0),
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &b,
|
||||
/// &[
|
||||
/// Token::NewtypeVariant {
|
||||
/// name: "E",
|
||||
/// variant: "B",
|
||||
/// },
|
||||
/// Token::U8(0),
|
||||
/// ],
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
NewtypeVariant {
|
||||
@@ -271,17 +280,20 @@ pub enum Token {
|
||||
/// After this header are the elements of the sequence, followed by
|
||||
/// `SeqEnd`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// let vec = vec!['a', 'b', 'c'];
|
||||
/// assert_tokens(&vec, &[
|
||||
/// Token::Seq { len: Some(3) },
|
||||
/// Token::Char('a'),
|
||||
/// Token::Char('b'),
|
||||
/// Token::Char('c'),
|
||||
/// Token::SeqEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &vec,
|
||||
/// &[
|
||||
/// Token::Seq { len: Some(3) },
|
||||
/// Token::Char('a'),
|
||||
/// Token::Char('b'),
|
||||
/// Token::Char('c'),
|
||||
/// Token::SeqEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// ```
|
||||
Seq { len: Option<usize> },
|
||||
|
||||
@@ -292,16 +304,19 @@ pub enum Token {
|
||||
///
|
||||
/// After this header are the elements of the tuple, followed by `TupleEnd`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// let tuple = ('a', 100);
|
||||
/// assert_tokens(&tuple, &[
|
||||
/// Token::Tuple { len: 2 },
|
||||
/// Token::Char('a'),
|
||||
/// Token::I32(100),
|
||||
/// Token::TupleEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &tuple,
|
||||
/// &[
|
||||
/// Token::Tuple { len: 2 },
|
||||
/// Token::Char('a'),
|
||||
/// Token::I32(100),
|
||||
/// Token::TupleEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// ```
|
||||
Tuple { len: usize },
|
||||
|
||||
@@ -313,8 +328,8 @@ pub enum Token {
|
||||
/// After this header are the fields of the tuple struct, followed by
|
||||
/// `TupleStructEnd`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
@@ -322,12 +337,15 @@ pub enum Token {
|
||||
/// struct T(u8, u8);
|
||||
///
|
||||
/// let t = T(0, 0);
|
||||
/// assert_tokens(&t, &[
|
||||
/// Token::TupleStruct { name: "T", len: 2 },
|
||||
/// Token::U8(0),
|
||||
/// Token::U8(0),
|
||||
/// Token::TupleStructEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &t,
|
||||
/// &[
|
||||
/// Token::TupleStruct { name: "T", len: 2 },
|
||||
/// Token::U8(0),
|
||||
/// Token::U8(0),
|
||||
/// Token::TupleStructEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
TupleStruct { name: &'static str, len: usize },
|
||||
@@ -340,8 +358,8 @@ pub enum Token {
|
||||
/// After this header are the fields of the tuple variant, followed by
|
||||
/// `TupleVariantEnd`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
@@ -351,12 +369,19 @@ pub enum Token {
|
||||
/// }
|
||||
///
|
||||
/// let c = E::C(0, 0);
|
||||
/// assert_tokens(&c, &[
|
||||
/// Token::TupleVariant { name: "E", variant: "C", len: 2 },
|
||||
/// Token::U8(0),
|
||||
/// Token::U8(0),
|
||||
/// Token::TupleVariantEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &c,
|
||||
/// &[
|
||||
/// Token::TupleVariant {
|
||||
/// name: "E",
|
||||
/// variant: "C",
|
||||
/// len: 2,
|
||||
/// },
|
||||
/// Token::U8(0),
|
||||
/// Token::U8(0),
|
||||
/// Token::TupleVariantEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
TupleVariant {
|
||||
@@ -372,7 +397,7 @@ pub enum Token {
|
||||
///
|
||||
/// After this header are the entries of the map, followed by `MapEnd`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// ```edition2021
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// use std::collections::BTreeMap;
|
||||
@@ -381,14 +406,17 @@ pub enum Token {
|
||||
/// map.insert('A', 65);
|
||||
/// map.insert('Z', 90);
|
||||
///
|
||||
/// assert_tokens(&map, &[
|
||||
/// Token::Map { len: Some(2) },
|
||||
/// Token::Char('A'),
|
||||
/// Token::I32(65),
|
||||
/// Token::Char('Z'),
|
||||
/// Token::I32(90),
|
||||
/// Token::MapEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &map,
|
||||
/// &[
|
||||
/// Token::Map { len: Some(2) },
|
||||
/// Token::Char('A'),
|
||||
/// Token::I32(65),
|
||||
/// Token::Char('Z'),
|
||||
/// Token::I32(90),
|
||||
/// Token::MapEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// ```
|
||||
Map { len: Option<usize> },
|
||||
|
||||
@@ -399,8 +427,8 @@ pub enum Token {
|
||||
///
|
||||
/// After this header are the fields of the struct, followed by `StructEnd`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
@@ -411,14 +439,17 @@ pub enum Token {
|
||||
/// }
|
||||
///
|
||||
/// let s = S { a: 0, b: 0 };
|
||||
/// assert_tokens(&s, &[
|
||||
/// Token::Struct { name: "S", len: 2 },
|
||||
/// Token::Str("a"),
|
||||
/// Token::U8(0),
|
||||
/// Token::Str("b"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &s,
|
||||
/// &[
|
||||
/// Token::Struct { name: "S", len: 2 },
|
||||
/// Token::Str("a"),
|
||||
/// Token::U8(0),
|
||||
/// Token::Str("b"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
Struct { name: &'static str, len: usize },
|
||||
@@ -431,8 +462,8 @@ pub enum Token {
|
||||
/// After this header are the fields of the struct variant, followed by
|
||||
/// `StructVariantEnd`.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
@@ -442,12 +473,19 @@ pub enum Token {
|
||||
/// }
|
||||
///
|
||||
/// let d = E::D { d: 0 };
|
||||
/// assert_tokens(&d, &[
|
||||
/// Token::StructVariant { name: "E", variant: "D", len: 1 },
|
||||
/// Token::Str("d"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructVariantEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &d,
|
||||
/// &[
|
||||
/// Token::StructVariant {
|
||||
/// name: "E",
|
||||
/// variant: "D",
|
||||
/// len: 1,
|
||||
/// },
|
||||
/// Token::Str("d"),
|
||||
/// Token::U8(0),
|
||||
/// Token::StructVariantEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
StructVariant {
|
||||
@@ -461,8 +499,8 @@ pub enum Token {
|
||||
|
||||
/// The header to an enum of the given name.
|
||||
///
|
||||
/// ```edition2018
|
||||
/// # use serde::{Serialize, Deserialize};
|
||||
/// ```edition2021
|
||||
/// # use serde_derive::{Deserialize, Serialize};
|
||||
/// # use serde_test::{assert_tokens, Token};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
@@ -475,38 +513,42 @@ pub enum Token {
|
||||
/// }
|
||||
///
|
||||
/// let a = E::A;
|
||||
/// assert_tokens(&a, &[
|
||||
/// Token::Enum { name: "E" },
|
||||
/// Token::Str("A"),
|
||||
/// Token::Unit,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &a,
|
||||
/// &[Token::Enum { name: "E" }, Token::Str("A"), Token::Unit],
|
||||
/// );
|
||||
///
|
||||
/// let b = E::B(0);
|
||||
/// assert_tokens(&b, &[
|
||||
/// Token::Enum { name: "E" },
|
||||
/// Token::Str("B"),
|
||||
/// Token::U8(0),
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &b,
|
||||
/// &[Token::Enum { name: "E" }, Token::Str("B"), Token::U8(0)],
|
||||
/// );
|
||||
///
|
||||
/// let c = E::C(0, 0);
|
||||
/// assert_tokens(&c, &[
|
||||
/// Token::Enum { name: "E" },
|
||||
/// Token::Str("C"),
|
||||
/// Token::Seq { len: Some(2) },
|
||||
/// Token::U8(0),
|
||||
/// Token::U8(0),
|
||||
/// Token::SeqEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &c,
|
||||
/// &[
|
||||
/// Token::Enum { name: "E" },
|
||||
/// Token::Str("C"),
|
||||
/// Token::Seq { len: Some(2) },
|
||||
/// Token::U8(0),
|
||||
/// Token::U8(0),
|
||||
/// Token::SeqEnd,
|
||||
/// ],
|
||||
/// );
|
||||
///
|
||||
/// let d = E::D { d: 0 };
|
||||
/// assert_tokens(&d, &[
|
||||
/// Token::Enum { name: "E" },
|
||||
/// Token::Str("D"),
|
||||
/// Token::Map { len: Some(1) },
|
||||
/// Token::Str("d"),
|
||||
/// Token::U8(0),
|
||||
/// Token::MapEnd,
|
||||
/// ]);
|
||||
/// assert_tokens(
|
||||
/// &d,
|
||||
/// &[
|
||||
/// Token::Enum { name: "E" },
|
||||
/// Token::Str("D"),
|
||||
/// Token::Map { len: Some(1) },
|
||||
/// Token::Str("d"),
|
||||
/// Token::U8(0),
|
||||
/// Token::MapEnd,
|
||||
/// ],
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
Enum { name: &'static str },
|
||||
|
||||
@@ -4,23 +4,18 @@ version = "0.0.0"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
build = "build.rs"
|
||||
|
||||
[features]
|
||||
expandtest = []
|
||||
unstable = ["serde/unstable"]
|
||||
|
||||
[dependencies]
|
||||
serde = { path = "../serde" }
|
||||
|
||||
[build-dependencies]
|
||||
toolchain_find = "0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
automod = "1.0.1"
|
||||
fnv = "1.0"
|
||||
macrotest = "=1.0.0"
|
||||
rustversion = "1.0"
|
||||
serde = { path = "../serde", features = ["rc", "derive"] }
|
||||
serde = { path = "../serde", features = ["rc"] }
|
||||
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
|
||||
serde_test = { path = "../serde_test" }
|
||||
trybuild = { version = "1.0.19", features = ["diff"] }
|
||||
trybuild = { version = "1.0.66", features = ["diff"] }
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
use std::process::{Command, ExitStatus, Stdio};
|
||||
|
||||
fn has_cargo_expand() -> bool {
|
||||
let cargo_expand = if cfg!(windows) {
|
||||
"cargo-expand.exe"
|
||||
} else {
|
||||
"cargo-expand"
|
||||
};
|
||||
|
||||
Command::new(cargo_expand)
|
||||
.arg("--version")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
.as_ref()
|
||||
.map(ExitStatus::success)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn has_rustfmt() -> bool {
|
||||
toolchain_find::find_installed_component("rustfmt").is_some()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if cfg!(feature = "expandtest") && has_cargo_expand() && has_rustfmt() {
|
||||
println!("cargo:rustc-cfg=expandtest");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
[package]
|
||||
name = "serde_derive_tests_no_std"
|
||||
version = "0.0.0"
|
||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
libc = { version = "0.2", default-features = false }
|
||||
serde = { path = "../../serde", default-features = false, features = ["derive"] }
|
||||
serde = { path = "../../serde", default-features = false }
|
||||
serde_derive = { path = "../../serde_derive" }
|
||||
|
||||
[workspace]
|
||||
|
||||
@@ -19,7 +19,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Unit;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#[cfg_attr(target_os = "emscripten", ignore)]
|
||||
#[rustversion::attr(not(nightly), ignore)]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
#[allow(unused_attributes)]
|
||||
#[test]
|
||||
fn ui() {
|
||||
let t = trybuild::TestCases::new();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,13 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum DeEnum<B, C, D> {
|
||||
Unit,
|
||||
Seq(i8, B, C, D),
|
||||
Map { a: i8, b: B, c: C, d: D },
|
||||
|
||||
// Make sure we can support more than one variant.
|
||||
_Unit2,
|
||||
_Seq2(i8, B, C, D),
|
||||
_Map2 { a: i8, b: B, c: C, d: D },
|
||||
}
|
||||
@@ -1,410 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
trait AssociatedType {
|
||||
type X;
|
||||
}
|
||||
impl AssociatedType for i32 {
|
||||
type X = i32;
|
||||
}
|
||||
struct DefaultTyParam<T: AssociatedType<X = i32> = i32> {
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<T: AssociatedType<X = i32>> _serde::Serialize for DefaultTyParam<T> {
|
||||
fn serialize<__S>(
|
||||
&self,
|
||||
__serializer: __S,
|
||||
) -> _serde::__private::Result<__S::Ok, __S::Error>
|
||||
where
|
||||
__S: _serde::Serializer,
|
||||
{
|
||||
let mut __serde_state = match _serde::Serializer::serialize_struct(
|
||||
__serializer,
|
||||
"DefaultTyParam",
|
||||
false as usize + 1,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeStruct::serialize_field(
|
||||
&mut __serde_state,
|
||||
"phantom",
|
||||
&self.phantom,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
_serde::ser::SerializeStruct::end(__serde_state)
|
||||
}
|
||||
}
|
||||
};
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<'de, T: AssociatedType<X = i32>> _serde::Deserialize<'de> for DefaultTyParam<T> {
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "field identifier")
|
||||
}
|
||||
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"phantom" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"phantom" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, T: AssociatedType<X = i32>> {
|
||||
marker: _serde::__private::PhantomData<DefaultTyParam<T>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, T: AssociatedType<X = i32>> _serde::de::Visitor<'de> for __Visitor<'de, T> {
|
||||
type Value = DefaultTyParam<T>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "struct DefaultTyParam")
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 = match match _serde::de::SeqAccess::next_element::<PhantomData<T>>(
|
||||
&mut __seq,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"struct DefaultTyParam with 1 element",
|
||||
));
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(DefaultTyParam { phantom: __field0 })
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: _serde::__private::Option<PhantomData<T>> =
|
||||
_serde::__private::None;
|
||||
while let _serde::__private::Some(__key) =
|
||||
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if _serde::__private::Option::is_some(&__field0) {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field(
|
||||
"phantom",
|
||||
),
|
||||
);
|
||||
}
|
||||
__field0 = _serde::__private::Some(
|
||||
match _serde::de::MapAccess::next_value::<PhantomData<T>>(
|
||||
&mut __map,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
let _ = match _serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(&mut __map)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
let __field0 = match __field0 {
|
||||
_serde::__private::Some(__field0) => __field0,
|
||||
_serde::__private::None => {
|
||||
match _serde::__private::de::missing_field("phantom") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(DefaultTyParam { phantom: __field0 })
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["phantom"];
|
||||
_serde::Deserializer::deserialize_struct(
|
||||
__deserializer,
|
||||
"DefaultTyParam",
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<DefaultTyParam<T>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
fn deserialize_in_place<__D>(
|
||||
__deserializer: __D,
|
||||
__place: &mut Self,
|
||||
) -> _serde::__private::Result<(), __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "field identifier")
|
||||
}
|
||||
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"phantom" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"phantom" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, 'place, T: AssociatedType<X = i32> + 'place> {
|
||||
place: &'place mut DefaultTyParam<T>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, 'place, T: AssociatedType<X = i32> + 'place> _serde::de::Visitor<'de>
|
||||
for __Visitor<'de, 'place, T>
|
||||
{
|
||||
type Value = ();
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "struct DefaultTyParam")
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
|
||||
&mut __seq,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.phantom),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"struct DefaultTyParam with 1 element",
|
||||
));
|
||||
}
|
||||
_serde::__private::Ok(())
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: bool = false;
|
||||
while let _serde::__private::Some(__key) =
|
||||
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if __field0 {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field(
|
||||
"phantom",
|
||||
),
|
||||
);
|
||||
}
|
||||
match _serde::de::MapAccess::next_value_seed(
|
||||
&mut __map,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.phantom),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
__field0 = true;
|
||||
}
|
||||
_ => {
|
||||
let _ = match _serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(&mut __map)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
if !__field0 {
|
||||
self.place.phantom = match _serde::__private::de::missing_field("phantom") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
};
|
||||
_serde::__private::Ok(())
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["phantom"];
|
||||
_serde::Deserializer::deserialize_struct(
|
||||
__deserializer,
|
||||
"DefaultTyParam",
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
place: __place,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
trait AssociatedType {
|
||||
type X;
|
||||
}
|
||||
|
||||
impl AssociatedType for i32 {
|
||||
type X = i32;
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct DefaultTyParam<T: AssociatedType<X = i32> = i32> {
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
@@ -1,590 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub enum GenericEnum<T, U> {
|
||||
Unit,
|
||||
NewType(T),
|
||||
Seq(T, U),
|
||||
Map { x: T, y: U },
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<T, U> _serde::Serialize for GenericEnum<T, U>
|
||||
where
|
||||
T: _serde::Serialize,
|
||||
U: _serde::Serialize,
|
||||
{
|
||||
fn serialize<__S>(
|
||||
&self,
|
||||
__serializer: __S,
|
||||
) -> _serde::__private::Result<__S::Ok, __S::Error>
|
||||
where
|
||||
__S: _serde::Serializer,
|
||||
{
|
||||
match *self {
|
||||
GenericEnum::Unit => _serde::Serializer::serialize_unit_variant(
|
||||
__serializer,
|
||||
"GenericEnum",
|
||||
0u32,
|
||||
"Unit",
|
||||
),
|
||||
GenericEnum::NewType(ref __field0) => {
|
||||
_serde::Serializer::serialize_newtype_variant(
|
||||
__serializer,
|
||||
"GenericEnum",
|
||||
1u32,
|
||||
"NewType",
|
||||
__field0,
|
||||
)
|
||||
}
|
||||
GenericEnum::Seq(ref __field0, ref __field1) => {
|
||||
let mut __serde_state = match _serde::Serializer::serialize_tuple_variant(
|
||||
__serializer,
|
||||
"GenericEnum",
|
||||
2u32,
|
||||
"Seq",
|
||||
0 + 1 + 1,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeTupleVariant::serialize_field(
|
||||
&mut __serde_state,
|
||||
__field0,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeTupleVariant::serialize_field(
|
||||
&mut __serde_state,
|
||||
__field1,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
_serde::ser::SerializeTupleVariant::end(__serde_state)
|
||||
}
|
||||
GenericEnum::Map { ref x, ref y } => {
|
||||
let mut __serde_state = match _serde::Serializer::serialize_struct_variant(
|
||||
__serializer,
|
||||
"GenericEnum",
|
||||
3u32,
|
||||
"Map",
|
||||
0 + 1 + 1,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeStructVariant::serialize_field(
|
||||
&mut __serde_state,
|
||||
"x",
|
||||
x,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeStructVariant::serialize_field(
|
||||
&mut __serde_state,
|
||||
"y",
|
||||
y,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
_serde::ser::SerializeStructVariant::end(__serde_state)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<'de, T, U> _serde::Deserialize<'de> for GenericEnum<T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__field1,
|
||||
__field2,
|
||||
__field3,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "variant identifier")
|
||||
}
|
||||
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
1u64 => _serde::__private::Ok(__Field::__field1),
|
||||
2u64 => _serde::__private::Ok(__Field::__field2),
|
||||
3u64 => _serde::__private::Ok(__Field::__field3),
|
||||
_ => _serde::__private::Err(_serde::de::Error::invalid_value(
|
||||
_serde::de::Unexpected::Unsigned(__value),
|
||||
&"variant index 0 <= i < 4",
|
||||
)),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"Unit" => _serde::__private::Ok(__Field::__field0),
|
||||
"NewType" => _serde::__private::Ok(__Field::__field1),
|
||||
"Seq" => _serde::__private::Ok(__Field::__field2),
|
||||
"Map" => _serde::__private::Ok(__Field::__field3),
|
||||
_ => _serde::__private::Err(_serde::de::Error::unknown_variant(
|
||||
__value, VARIANTS,
|
||||
)),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"Unit" => _serde::__private::Ok(__Field::__field0),
|
||||
b"NewType" => _serde::__private::Ok(__Field::__field1),
|
||||
b"Seq" => _serde::__private::Ok(__Field::__field2),
|
||||
b"Map" => _serde::__private::Ok(__Field::__field3),
|
||||
_ => {
|
||||
let __value = &_serde::__private::from_utf8_lossy(__value);
|
||||
_serde::__private::Err(_serde::de::Error::unknown_variant(
|
||||
__value, VARIANTS,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
marker: _serde::__private::PhantomData<GenericEnum<T, U>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, T, U> _serde::de::Visitor<'de> for __Visitor<'de, T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = GenericEnum<T, U>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "enum GenericEnum")
|
||||
}
|
||||
fn visit_enum<__A>(
|
||||
self,
|
||||
__data: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::EnumAccess<'de>,
|
||||
{
|
||||
match match _serde::de::EnumAccess::variant(__data) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
(__Field::__field0, __variant) => {
|
||||
match _serde::de::VariantAccess::unit_variant(__variant) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(GenericEnum::Unit)
|
||||
}
|
||||
(__Field::__field1, __variant) => _serde::__private::Result::map(
|
||||
_serde::de::VariantAccess::newtype_variant::<T>(__variant),
|
||||
GenericEnum::NewType,
|
||||
),
|
||||
(__Field::__field2, __variant) => {
|
||||
struct __Visitor<'de, T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
marker: _serde::__private::PhantomData<GenericEnum<T, U>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, T, U> _serde::de::Visitor<'de> for __Visitor<'de, T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = GenericEnum<T, U>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result
|
||||
{
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"tuple variant GenericEnum::Seq",
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 = match match _serde::de::SeqAccess::next_element::<
|
||||
T,
|
||||
>(
|
||||
&mut __seq
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde :: __private :: Err (_serde :: de :: Error :: invalid_length (0usize , & "tuple variant GenericEnum::Seq with 2 elements")) ;
|
||||
}
|
||||
};
|
||||
let __field1 = match match _serde::de::SeqAccess::next_element::<
|
||||
U,
|
||||
>(
|
||||
&mut __seq
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde :: __private :: Err (_serde :: de :: Error :: invalid_length (1usize , & "tuple variant GenericEnum::Seq with 2 elements")) ;
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(GenericEnum::Seq(__field0, __field1))
|
||||
}
|
||||
}
|
||||
_serde::de::VariantAccess::tuple_variant(
|
||||
__variant,
|
||||
2usize,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<GenericEnum<T, U>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
(__Field::__field3, __variant) => {
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__field1,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result
|
||||
{
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"field identifier",
|
||||
)
|
||||
}
|
||||
fn visit_u64<__E>(
|
||||
self,
|
||||
__value: u64,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
1u64 => _serde::__private::Ok(__Field::__field1),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"x" => _serde::__private::Ok(__Field::__field0),
|
||||
"y" => _serde::__private::Ok(__Field::__field1),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"x" => _serde::__private::Ok(__Field::__field0),
|
||||
b"y" => _serde::__private::Ok(__Field::__field1),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(
|
||||
__deserializer,
|
||||
__FieldVisitor,
|
||||
)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
marker: _serde::__private::PhantomData<GenericEnum<T, U>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, T, U> _serde::de::Visitor<'de> for __Visitor<'de, T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = GenericEnum<T, U>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result
|
||||
{
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"struct variant GenericEnum::Map",
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 = match match _serde::de::SeqAccess::next_element::<
|
||||
T,
|
||||
>(
|
||||
&mut __seq
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde :: __private :: Err (_serde :: de :: Error :: invalid_length (0usize , & "struct variant GenericEnum::Map with 2 elements")) ;
|
||||
}
|
||||
};
|
||||
let __field1 = match match _serde::de::SeqAccess::next_element::<
|
||||
U,
|
||||
>(
|
||||
&mut __seq
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde :: __private :: Err (_serde :: de :: Error :: invalid_length (1usize , & "struct variant GenericEnum::Map with 2 elements")) ;
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(GenericEnum::Map {
|
||||
x: __field0,
|
||||
y: __field1,
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: _serde::__private::Option<T> =
|
||||
_serde::__private::None;
|
||||
let mut __field1: _serde::__private::Option<U> =
|
||||
_serde::__private::None;
|
||||
while let _serde::__private::Some(__key) =
|
||||
match _serde::de::MapAccess::next_key::<__Field>(&mut __map)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if _serde::__private::Option::is_some(&__field0) {
|
||||
return _serde :: __private :: Err (< __A :: Error as _serde :: de :: Error > :: duplicate_field ("x")) ;
|
||||
}
|
||||
__field0 = _serde::__private::Some(
|
||||
match _serde::de::MapAccess::next_value::<T>(
|
||||
&mut __map,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
__Field::__field1 => {
|
||||
if _serde::__private::Option::is_some(&__field1) {
|
||||
return _serde :: __private :: Err (< __A :: Error as _serde :: de :: Error > :: duplicate_field ("y")) ;
|
||||
}
|
||||
__field1 = _serde::__private::Some(
|
||||
match _serde::de::MapAccess::next_value::<U>(
|
||||
&mut __map,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
let _ = match _serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(
|
||||
&mut __map
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
let __field0 = match __field0 {
|
||||
_serde::__private::Some(__field0) => __field0,
|
||||
_serde::__private::None => {
|
||||
match _serde::__private::de::missing_field("x") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let __field1 = match __field1 {
|
||||
_serde::__private::Some(__field1) => __field1,
|
||||
_serde::__private::None => {
|
||||
match _serde::__private::de::missing_field("y") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(GenericEnum::Map {
|
||||
x: __field0,
|
||||
y: __field1,
|
||||
})
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["x", "y"];
|
||||
_serde::de::VariantAccess::struct_variant(
|
||||
__variant,
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<GenericEnum<T, U>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const VARIANTS: &'static [&'static str] = &["Unit", "NewType", "Seq", "Map"];
|
||||
_serde::Deserializer::deserialize_enum(
|
||||
__deserializer,
|
||||
"GenericEnum",
|
||||
VARIANTS,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<GenericEnum<T, U>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum GenericEnum<T, U> {
|
||||
Unit,
|
||||
NewType(T),
|
||||
Seq(T, U),
|
||||
Map { x: T, y: U },
|
||||
}
|
||||
@@ -1,594 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub struct GenericStruct<T> {
|
||||
x: T,
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<T> _serde::Serialize for GenericStruct<T>
|
||||
where
|
||||
T: _serde::Serialize,
|
||||
{
|
||||
fn serialize<__S>(
|
||||
&self,
|
||||
__serializer: __S,
|
||||
) -> _serde::__private::Result<__S::Ok, __S::Error>
|
||||
where
|
||||
__S: _serde::Serializer,
|
||||
{
|
||||
let mut __serde_state = match _serde::Serializer::serialize_struct(
|
||||
__serializer,
|
||||
"GenericStruct",
|
||||
false as usize + 1,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "x", &self.x) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
_serde::ser::SerializeStruct::end(__serde_state)
|
||||
}
|
||||
}
|
||||
};
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<'de, T> _serde::Deserialize<'de> for GenericStruct<T>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "field identifier")
|
||||
}
|
||||
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"x" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"x" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, T>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
marker: _serde::__private::PhantomData<GenericStruct<T>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, T> _serde::de::Visitor<'de> for __Visitor<'de, T>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = GenericStruct<T>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "struct GenericStruct")
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 = match match _serde::de::SeqAccess::next_element::<T>(&mut __seq)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"struct GenericStruct with 1 element",
|
||||
));
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(GenericStruct { x: __field0 })
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: _serde::__private::Option<T> = _serde::__private::None;
|
||||
while let _serde::__private::Some(__key) =
|
||||
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if _serde::__private::Option::is_some(&__field0) {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("x"),
|
||||
);
|
||||
}
|
||||
__field0 = _serde::__private::Some(
|
||||
match _serde::de::MapAccess::next_value::<T>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
let _ = match _serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(&mut __map)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
let __field0 = match __field0 {
|
||||
_serde::__private::Some(__field0) => __field0,
|
||||
_serde::__private::None => {
|
||||
match _serde::__private::de::missing_field("x") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(GenericStruct { x: __field0 })
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["x"];
|
||||
_serde::Deserializer::deserialize_struct(
|
||||
__deserializer,
|
||||
"GenericStruct",
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<GenericStruct<T>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
fn deserialize_in_place<__D>(
|
||||
__deserializer: __D,
|
||||
__place: &mut Self,
|
||||
) -> _serde::__private::Result<(), __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "field identifier")
|
||||
}
|
||||
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"x" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"x" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, 'place, T: 'place>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
place: &'place mut GenericStruct<T>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, 'place, T: 'place> _serde::de::Visitor<'de> for __Visitor<'de, 'place, T>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = ();
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "struct GenericStruct")
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
|
||||
&mut __seq,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.x),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"struct GenericStruct with 1 element",
|
||||
));
|
||||
}
|
||||
_serde::__private::Ok(())
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: bool = false;
|
||||
while let _serde::__private::Some(__key) =
|
||||
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if __field0 {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("x"),
|
||||
);
|
||||
}
|
||||
match _serde::de::MapAccess::next_value_seed(
|
||||
&mut __map,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.x),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
__field0 = true;
|
||||
}
|
||||
_ => {
|
||||
let _ = match _serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(&mut __map)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
if !__field0 {
|
||||
self.place.x = match _serde::__private::de::missing_field("x") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
};
|
||||
_serde::__private::Ok(())
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["x"];
|
||||
_serde::Deserializer::deserialize_struct(
|
||||
__deserializer,
|
||||
"GenericStruct",
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
place: __place,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
pub struct GenericNewTypeStruct<T>(T);
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<T> _serde::Serialize for GenericNewTypeStruct<T>
|
||||
where
|
||||
T: _serde::Serialize,
|
||||
{
|
||||
fn serialize<__S>(
|
||||
&self,
|
||||
__serializer: __S,
|
||||
) -> _serde::__private::Result<__S::Ok, __S::Error>
|
||||
where
|
||||
__S: _serde::Serializer,
|
||||
{
|
||||
_serde::Serializer::serialize_newtype_struct(
|
||||
__serializer,
|
||||
"GenericNewTypeStruct",
|
||||
&self.0,
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<'de, T> _serde::Deserialize<'de> for GenericNewTypeStruct<T>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
struct __Visitor<'de, T>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
marker: _serde::__private::PhantomData<GenericNewTypeStruct<T>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, T> _serde::de::Visitor<'de> for __Visitor<'de, T>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = GenericNewTypeStruct<T>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"tuple struct GenericNewTypeStruct",
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
fn visit_newtype_struct<__E>(
|
||||
self,
|
||||
__e: __E,
|
||||
) -> _serde::__private::Result<Self::Value, __E::Error>
|
||||
where
|
||||
__E: _serde::Deserializer<'de>,
|
||||
{
|
||||
let __field0: T = match <T as _serde::Deserialize>::deserialize(__e) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(GenericNewTypeStruct(__field0))
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 = match match _serde::de::SeqAccess::next_element::<T>(&mut __seq)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"tuple struct GenericNewTypeStruct with 1 element",
|
||||
));
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(GenericNewTypeStruct(__field0))
|
||||
}
|
||||
}
|
||||
_serde::Deserializer::deserialize_newtype_struct(
|
||||
__deserializer,
|
||||
"GenericNewTypeStruct",
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<GenericNewTypeStruct<T>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
fn deserialize_in_place<__D>(
|
||||
__deserializer: __D,
|
||||
__place: &mut Self,
|
||||
) -> _serde::__private::Result<(), __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
struct __Visitor<'de, 'place, T: 'place>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
place: &'place mut GenericNewTypeStruct<T>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, 'place, T: 'place> _serde::de::Visitor<'de> for __Visitor<'de, 'place, T>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = ();
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"tuple struct GenericNewTypeStruct",
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
fn visit_newtype_struct<__E>(
|
||||
self,
|
||||
__e: __E,
|
||||
) -> _serde::__private::Result<Self::Value, __E::Error>
|
||||
where
|
||||
__E: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserialize::deserialize_in_place(__e, &mut self.place.0)
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
|
||||
&mut __seq,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.0),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"tuple struct GenericNewTypeStruct with 1 element",
|
||||
));
|
||||
}
|
||||
_serde::__private::Ok(())
|
||||
}
|
||||
}
|
||||
_serde::Deserializer::deserialize_newtype_struct(
|
||||
__deserializer,
|
||||
"GenericNewTypeStruct",
|
||||
__Visitor {
|
||||
place: __place,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct GenericStruct<T> {
|
||||
x: T,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct GenericNewTypeStruct<T>(T);
|
||||
@@ -1,172 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub struct GenericTupleStruct<T, U>(T, U);
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<'de, T, U> _serde::Deserialize<'de> for GenericTupleStruct<T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
struct __Visitor<'de, T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
marker: _serde::__private::PhantomData<GenericTupleStruct<T, U>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, T, U> _serde::de::Visitor<'de> for __Visitor<'de, T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = GenericTupleStruct<T, U>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"tuple struct GenericTupleStruct",
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 = match match _serde::de::SeqAccess::next_element::<T>(&mut __seq)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"tuple struct GenericTupleStruct with 2 elements",
|
||||
));
|
||||
}
|
||||
};
|
||||
let __field1 = match match _serde::de::SeqAccess::next_element::<U>(&mut __seq)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
1usize,
|
||||
&"tuple struct GenericTupleStruct with 2 elements",
|
||||
));
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(GenericTupleStruct(__field0, __field1))
|
||||
}
|
||||
}
|
||||
_serde::Deserializer::deserialize_tuple_struct(
|
||||
__deserializer,
|
||||
"GenericTupleStruct",
|
||||
2usize,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<GenericTupleStruct<T, U>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
fn deserialize_in_place<__D>(
|
||||
__deserializer: __D,
|
||||
__place: &mut Self,
|
||||
) -> _serde::__private::Result<(), __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
struct __Visitor<'de, 'place, T: 'place, U: 'place>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
place: &'place mut GenericTupleStruct<T, U>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, 'place, T: 'place, U: 'place> _serde::de::Visitor<'de> for __Visitor<'de, 'place, T, U>
|
||||
where
|
||||
T: _serde::Deserialize<'de>,
|
||||
U: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = ();
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"tuple struct GenericTupleStruct",
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
|
||||
&mut __seq,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.0),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"tuple struct GenericTupleStruct with 2 elements",
|
||||
));
|
||||
}
|
||||
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
|
||||
&mut __seq,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.1),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
1usize,
|
||||
&"tuple struct GenericTupleStruct with 2 elements",
|
||||
));
|
||||
}
|
||||
_serde::__private::Ok(())
|
||||
}
|
||||
}
|
||||
_serde::Deserializer::deserialize_tuple_struct(
|
||||
__deserializer,
|
||||
"GenericTupleStruct",
|
||||
2usize,
|
||||
__Visitor {
|
||||
place: __place,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GenericTupleStruct<T, U>(T, U);
|
||||
@@ -1,607 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
enum Lifetimes<'a> {
|
||||
LifetimeSeq(&'a i32),
|
||||
NoLifetimeSeq(i32),
|
||||
LifetimeMap { a: &'a i32 },
|
||||
NoLifetimeMap { a: i32 },
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<'a> _serde::Serialize for Lifetimes<'a> {
|
||||
fn serialize<__S>(
|
||||
&self,
|
||||
__serializer: __S,
|
||||
) -> _serde::__private::Result<__S::Ok, __S::Error>
|
||||
where
|
||||
__S: _serde::Serializer,
|
||||
{
|
||||
match *self {
|
||||
Lifetimes::LifetimeSeq(ref __field0) => {
|
||||
_serde::Serializer::serialize_newtype_variant(
|
||||
__serializer,
|
||||
"Lifetimes",
|
||||
0u32,
|
||||
"LifetimeSeq",
|
||||
__field0,
|
||||
)
|
||||
}
|
||||
Lifetimes::NoLifetimeSeq(ref __field0) => {
|
||||
_serde::Serializer::serialize_newtype_variant(
|
||||
__serializer,
|
||||
"Lifetimes",
|
||||
1u32,
|
||||
"NoLifetimeSeq",
|
||||
__field0,
|
||||
)
|
||||
}
|
||||
Lifetimes::LifetimeMap { ref a } => {
|
||||
let mut __serde_state = match _serde::Serializer::serialize_struct_variant(
|
||||
__serializer,
|
||||
"Lifetimes",
|
||||
2u32,
|
||||
"LifetimeMap",
|
||||
0 + 1,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeStructVariant::serialize_field(
|
||||
&mut __serde_state,
|
||||
"a",
|
||||
a,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
_serde::ser::SerializeStructVariant::end(__serde_state)
|
||||
}
|
||||
Lifetimes::NoLifetimeMap { ref a } => {
|
||||
let mut __serde_state = match _serde::Serializer::serialize_struct_variant(
|
||||
__serializer,
|
||||
"Lifetimes",
|
||||
3u32,
|
||||
"NoLifetimeMap",
|
||||
0 + 1,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeStructVariant::serialize_field(
|
||||
&mut __serde_state,
|
||||
"a",
|
||||
a,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
_serde::ser::SerializeStructVariant::end(__serde_state)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<'de, 'a> _serde::Deserialize<'de> for Lifetimes<'a> {
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__field1,
|
||||
__field2,
|
||||
__field3,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "variant identifier")
|
||||
}
|
||||
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
1u64 => _serde::__private::Ok(__Field::__field1),
|
||||
2u64 => _serde::__private::Ok(__Field::__field2),
|
||||
3u64 => _serde::__private::Ok(__Field::__field3),
|
||||
_ => _serde::__private::Err(_serde::de::Error::invalid_value(
|
||||
_serde::de::Unexpected::Unsigned(__value),
|
||||
&"variant index 0 <= i < 4",
|
||||
)),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"LifetimeSeq" => _serde::__private::Ok(__Field::__field0),
|
||||
"NoLifetimeSeq" => _serde::__private::Ok(__Field::__field1),
|
||||
"LifetimeMap" => _serde::__private::Ok(__Field::__field2),
|
||||
"NoLifetimeMap" => _serde::__private::Ok(__Field::__field3),
|
||||
_ => _serde::__private::Err(_serde::de::Error::unknown_variant(
|
||||
__value, VARIANTS,
|
||||
)),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"LifetimeSeq" => _serde::__private::Ok(__Field::__field0),
|
||||
b"NoLifetimeSeq" => _serde::__private::Ok(__Field::__field1),
|
||||
b"LifetimeMap" => _serde::__private::Ok(__Field::__field2),
|
||||
b"NoLifetimeMap" => _serde::__private::Ok(__Field::__field3),
|
||||
_ => {
|
||||
let __value = &_serde::__private::from_utf8_lossy(__value);
|
||||
_serde::__private::Err(_serde::de::Error::unknown_variant(
|
||||
__value, VARIANTS,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, 'a> {
|
||||
marker: _serde::__private::PhantomData<Lifetimes<'a>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, 'a> _serde::de::Visitor<'de> for __Visitor<'de, 'a> {
|
||||
type Value = Lifetimes<'a>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "enum Lifetimes")
|
||||
}
|
||||
fn visit_enum<__A>(
|
||||
self,
|
||||
__data: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::EnumAccess<'de>,
|
||||
{
|
||||
match match _serde::de::EnumAccess::variant(__data) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
(__Field::__field0, __variant) => _serde::__private::Result::map(
|
||||
_serde::de::VariantAccess::newtype_variant::<&'a i32>(__variant),
|
||||
Lifetimes::LifetimeSeq,
|
||||
),
|
||||
(__Field::__field1, __variant) => _serde::__private::Result::map(
|
||||
_serde::de::VariantAccess::newtype_variant::<i32>(__variant),
|
||||
Lifetimes::NoLifetimeSeq,
|
||||
),
|
||||
(__Field::__field2, __variant) => {
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result
|
||||
{
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"field identifier",
|
||||
)
|
||||
}
|
||||
fn visit_u64<__E>(
|
||||
self,
|
||||
__value: u64,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"a" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"a" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(
|
||||
__deserializer,
|
||||
__FieldVisitor,
|
||||
)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, 'a> {
|
||||
marker: _serde::__private::PhantomData<Lifetimes<'a>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, 'a> _serde::de::Visitor<'de> for __Visitor<'de, 'a> {
|
||||
type Value = Lifetimes<'a>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result
|
||||
{
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"struct variant Lifetimes::LifetimeMap",
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 = match match _serde::de::SeqAccess::next_element::<
|
||||
&'a i32,
|
||||
>(
|
||||
&mut __seq
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde :: __private :: Err (_serde :: de :: Error :: invalid_length (0usize , & "struct variant Lifetimes::LifetimeMap with 1 element")) ;
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(Lifetimes::LifetimeMap { a: __field0 })
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: _serde::__private::Option<&'a i32> =
|
||||
_serde::__private::None;
|
||||
while let _serde::__private::Some(__key) =
|
||||
match _serde::de::MapAccess::next_key::<__Field>(&mut __map)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if _serde::__private::Option::is_some(&__field0) {
|
||||
return _serde :: __private :: Err (< __A :: Error as _serde :: de :: Error > :: duplicate_field ("a")) ;
|
||||
}
|
||||
__field0 = _serde::__private::Some(
|
||||
match _serde::de::MapAccess::next_value::<&'a i32>(
|
||||
&mut __map,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
let _ = match _serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(
|
||||
&mut __map
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
let __field0 = match __field0 {
|
||||
_serde::__private::Some(__field0) => __field0,
|
||||
_serde::__private::None => {
|
||||
match _serde::__private::de::missing_field("a") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(Lifetimes::LifetimeMap { a: __field0 })
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["a"];
|
||||
_serde::de::VariantAccess::struct_variant(
|
||||
__variant,
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<Lifetimes<'a>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
(__Field::__field3, __variant) => {
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result
|
||||
{
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"field identifier",
|
||||
)
|
||||
}
|
||||
fn visit_u64<__E>(
|
||||
self,
|
||||
__value: u64,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"a" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"a" => _serde::__private::Ok(__Field::__field0),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(
|
||||
__deserializer,
|
||||
__FieldVisitor,
|
||||
)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, 'a> {
|
||||
marker: _serde::__private::PhantomData<Lifetimes<'a>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, 'a> _serde::de::Visitor<'de> for __Visitor<'de, 'a> {
|
||||
type Value = Lifetimes<'a>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result
|
||||
{
|
||||
_serde::__private::Formatter::write_str(
|
||||
__formatter,
|
||||
"struct variant Lifetimes::NoLifetimeMap",
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 = match match _serde::de::SeqAccess::next_element::<
|
||||
i32,
|
||||
>(
|
||||
&mut __seq
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde :: __private :: Err (_serde :: de :: Error :: invalid_length (0usize , & "struct variant Lifetimes::NoLifetimeMap with 1 element")) ;
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(Lifetimes::NoLifetimeMap { a: __field0 })
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: _serde::__private::Option<i32> =
|
||||
_serde::__private::None;
|
||||
while let _serde::__private::Some(__key) =
|
||||
match _serde::de::MapAccess::next_key::<__Field>(&mut __map)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if _serde::__private::Option::is_some(&__field0) {
|
||||
return _serde :: __private :: Err (< __A :: Error as _serde :: de :: Error > :: duplicate_field ("a")) ;
|
||||
}
|
||||
__field0 = _serde::__private::Some(
|
||||
match _serde::de::MapAccess::next_value::<i32>(
|
||||
&mut __map,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
let _ = match _serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(
|
||||
&mut __map
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
let __field0 = match __field0 {
|
||||
_serde::__private::Some(__field0) => __field0,
|
||||
_serde::__private::None => {
|
||||
match _serde::__private::de::missing_field("a") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(Lifetimes::NoLifetimeMap { a: __field0 })
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["a"];
|
||||
_serde::de::VariantAccess::struct_variant(
|
||||
__variant,
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<Lifetimes<'a>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const VARIANTS: &'static [&'static str] = &[
|
||||
"LifetimeSeq",
|
||||
"NoLifetimeSeq",
|
||||
"LifetimeMap",
|
||||
"NoLifetimeMap",
|
||||
];
|
||||
_serde::Deserializer::deserialize_enum(
|
||||
__deserializer,
|
||||
"Lifetimes",
|
||||
VARIANTS,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<Lifetimes<'a>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Lifetimes<'a> {
|
||||
LifetimeSeq(&'a i32),
|
||||
NoLifetimeSeq(i32),
|
||||
LifetimeMap { a: &'a i32 },
|
||||
NoLifetimeMap { a: i32 },
|
||||
}
|
||||
@@ -1,628 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
struct SerNamedMap<'a, 'b, A: 'a, B: 'b, C> {
|
||||
a: &'a A,
|
||||
b: &'b mut B,
|
||||
c: C,
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<'a, 'b, A: 'a, B: 'b, C> _serde::Serialize for SerNamedMap<'a, 'b, A, B, C>
|
||||
where
|
||||
A: _serde::Serialize,
|
||||
B: _serde::Serialize,
|
||||
C: _serde::Serialize,
|
||||
{
|
||||
fn serialize<__S>(
|
||||
&self,
|
||||
__serializer: __S,
|
||||
) -> _serde::__private::Result<__S::Ok, __S::Error>
|
||||
where
|
||||
__S: _serde::Serializer,
|
||||
{
|
||||
let mut __serde_state = match _serde::Serializer::serialize_struct(
|
||||
__serializer,
|
||||
"SerNamedMap",
|
||||
false as usize + 1 + 1 + 1,
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "a", &self.a) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "b", &self.b) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
match _serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "c", &self.c) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
_serde::ser::SerializeStruct::end(__serde_state)
|
||||
}
|
||||
}
|
||||
};
|
||||
struct DeNamedMap<A, B, C> {
|
||||
a: A,
|
||||
b: B,
|
||||
c: C,
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||
const _: () = {
|
||||
#[allow(unused_extern_crates, clippy::useless_attribute)]
|
||||
extern crate serde as _serde;
|
||||
#[automatically_derived]
|
||||
impl<'de, A, B, C> _serde::Deserialize<'de> for DeNamedMap<A, B, C>
|
||||
where
|
||||
A: _serde::Deserialize<'de>,
|
||||
B: _serde::Deserialize<'de>,
|
||||
C: _serde::Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__field1,
|
||||
__field2,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "field identifier")
|
||||
}
|
||||
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
1u64 => _serde::__private::Ok(__Field::__field1),
|
||||
2u64 => _serde::__private::Ok(__Field::__field2),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"a" => _serde::__private::Ok(__Field::__field0),
|
||||
"b" => _serde::__private::Ok(__Field::__field1),
|
||||
"c" => _serde::__private::Ok(__Field::__field2),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"a" => _serde::__private::Ok(__Field::__field0),
|
||||
b"b" => _serde::__private::Ok(__Field::__field1),
|
||||
b"c" => _serde::__private::Ok(__Field::__field2),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, A, B, C>
|
||||
where
|
||||
A: _serde::Deserialize<'de>,
|
||||
B: _serde::Deserialize<'de>,
|
||||
C: _serde::Deserialize<'de>,
|
||||
{
|
||||
marker: _serde::__private::PhantomData<DeNamedMap<A, B, C>>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, A, B, C> _serde::de::Visitor<'de> for __Visitor<'de, A, B, C>
|
||||
where
|
||||
A: _serde::Deserialize<'de>,
|
||||
B: _serde::Deserialize<'de>,
|
||||
C: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = DeNamedMap<A, B, C>;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "struct DeNamedMap")
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let __field0 = match match _serde::de::SeqAccess::next_element::<A>(&mut __seq)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"struct DeNamedMap with 3 elements",
|
||||
));
|
||||
}
|
||||
};
|
||||
let __field1 = match match _serde::de::SeqAccess::next_element::<B>(&mut __seq)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
1usize,
|
||||
&"struct DeNamedMap with 3 elements",
|
||||
));
|
||||
}
|
||||
};
|
||||
let __field2 = match match _serde::de::SeqAccess::next_element::<C>(&mut __seq)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
_serde::__private::Some(__value) => __value,
|
||||
_serde::__private::None => {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
2usize,
|
||||
&"struct DeNamedMap with 3 elements",
|
||||
));
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(DeNamedMap {
|
||||
a: __field0,
|
||||
b: __field1,
|
||||
c: __field2,
|
||||
})
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: _serde::__private::Option<A> = _serde::__private::None;
|
||||
let mut __field1: _serde::__private::Option<B> = _serde::__private::None;
|
||||
let mut __field2: _serde::__private::Option<C> = _serde::__private::None;
|
||||
while let _serde::__private::Some(__key) =
|
||||
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if _serde::__private::Option::is_some(&__field0) {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("a"),
|
||||
);
|
||||
}
|
||||
__field0 = _serde::__private::Some(
|
||||
match _serde::de::MapAccess::next_value::<A>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
__Field::__field1 => {
|
||||
if _serde::__private::Option::is_some(&__field1) {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("b"),
|
||||
);
|
||||
}
|
||||
__field1 = _serde::__private::Some(
|
||||
match _serde::de::MapAccess::next_value::<B>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
__Field::__field2 => {
|
||||
if _serde::__private::Option::is_some(&__field2) {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("c"),
|
||||
);
|
||||
}
|
||||
__field2 = _serde::__private::Some(
|
||||
match _serde::de::MapAccess::next_value::<C>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
let _ = match _serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(&mut __map)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
let __field0 = match __field0 {
|
||||
_serde::__private::Some(__field0) => __field0,
|
||||
_serde::__private::None => {
|
||||
match _serde::__private::de::missing_field("a") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let __field1 = match __field1 {
|
||||
_serde::__private::Some(__field1) => __field1,
|
||||
_serde::__private::None => {
|
||||
match _serde::__private::de::missing_field("b") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let __field2 = match __field2 {
|
||||
_serde::__private::Some(__field2) => __field2,
|
||||
_serde::__private::None => {
|
||||
match _serde::__private::de::missing_field("c") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_serde::__private::Ok(DeNamedMap {
|
||||
a: __field0,
|
||||
b: __field1,
|
||||
c: __field2,
|
||||
})
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["a", "b", "c"];
|
||||
_serde::Deserializer::deserialize_struct(
|
||||
__deserializer,
|
||||
"DeNamedMap",
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
marker: _serde::__private::PhantomData::<DeNamedMap<A, B, C>>,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
fn deserialize_in_place<__D>(
|
||||
__deserializer: __D,
|
||||
__place: &mut Self,
|
||||
) -> _serde::__private::Result<(), __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
__field0,
|
||||
__field1,
|
||||
__field2,
|
||||
__ignore,
|
||||
}
|
||||
struct __FieldVisitor;
|
||||
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
|
||||
type Value = __Field;
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "field identifier")
|
||||
}
|
||||
fn visit_u64<__E>(self, __value: u64) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
0u64 => _serde::__private::Ok(__Field::__field0),
|
||||
1u64 => _serde::__private::Ok(__Field::__field1),
|
||||
2u64 => _serde::__private::Ok(__Field::__field2),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_str<__E>(
|
||||
self,
|
||||
__value: &str,
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
"a" => _serde::__private::Ok(__Field::__field0),
|
||||
"b" => _serde::__private::Ok(__Field::__field1),
|
||||
"c" => _serde::__private::Ok(__Field::__field2),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<__E>(
|
||||
self,
|
||||
__value: &[u8],
|
||||
) -> _serde::__private::Result<Self::Value, __E>
|
||||
where
|
||||
__E: _serde::de::Error,
|
||||
{
|
||||
match __value {
|
||||
b"a" => _serde::__private::Ok(__Field::__field0),
|
||||
b"b" => _serde::__private::Ok(__Field::__field1),
|
||||
b"c" => _serde::__private::Ok(__Field::__field2),
|
||||
_ => _serde::__private::Ok(__Field::__ignore),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> _serde::Deserialize<'de> for __Field {
|
||||
#[inline]
|
||||
fn deserialize<__D>(
|
||||
__deserializer: __D,
|
||||
) -> _serde::__private::Result<Self, __D::Error>
|
||||
where
|
||||
__D: _serde::Deserializer<'de>,
|
||||
{
|
||||
_serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor)
|
||||
}
|
||||
}
|
||||
struct __Visitor<'de, 'place, A: 'place, B: 'place, C: 'place>
|
||||
where
|
||||
A: _serde::Deserialize<'de>,
|
||||
B: _serde::Deserialize<'de>,
|
||||
C: _serde::Deserialize<'de>,
|
||||
{
|
||||
place: &'place mut DeNamedMap<A, B, C>,
|
||||
lifetime: _serde::__private::PhantomData<&'de ()>,
|
||||
}
|
||||
impl<'de, 'place, A: 'place, B: 'place, C: 'place> _serde::de::Visitor<'de>
|
||||
for __Visitor<'de, 'place, A, B, C>
|
||||
where
|
||||
A: _serde::Deserialize<'de>,
|
||||
B: _serde::Deserialize<'de>,
|
||||
C: _serde::Deserialize<'de>,
|
||||
{
|
||||
type Value = ();
|
||||
fn expecting(
|
||||
&self,
|
||||
__formatter: &mut _serde::__private::Formatter,
|
||||
) -> _serde::__private::fmt::Result {
|
||||
_serde::__private::Formatter::write_str(__formatter, "struct DeNamedMap")
|
||||
}
|
||||
#[inline]
|
||||
fn visit_seq<__A>(
|
||||
self,
|
||||
mut __seq: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::SeqAccess<'de>,
|
||||
{
|
||||
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
|
||||
&mut __seq,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.a),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"struct DeNamedMap with 3 elements",
|
||||
));
|
||||
}
|
||||
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
|
||||
&mut __seq,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.b),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
1usize,
|
||||
&"struct DeNamedMap with 3 elements",
|
||||
));
|
||||
}
|
||||
if let _serde::__private::None = match _serde::de::SeqAccess::next_element_seed(
|
||||
&mut __seq,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.c),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
} {
|
||||
return _serde::__private::Err(_serde::de::Error::invalid_length(
|
||||
2usize,
|
||||
&"struct DeNamedMap with 3 elements",
|
||||
));
|
||||
}
|
||||
_serde::__private::Ok(())
|
||||
}
|
||||
#[inline]
|
||||
fn visit_map<__A>(
|
||||
self,
|
||||
mut __map: __A,
|
||||
) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||
where
|
||||
__A: _serde::de::MapAccess<'de>,
|
||||
{
|
||||
let mut __field0: bool = false;
|
||||
let mut __field1: bool = false;
|
||||
let mut __field2: bool = false;
|
||||
while let _serde::__private::Some(__key) =
|
||||
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
}
|
||||
{
|
||||
match __key {
|
||||
__Field::__field0 => {
|
||||
if __field0 {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("a"),
|
||||
);
|
||||
}
|
||||
match _serde::de::MapAccess::next_value_seed(
|
||||
&mut __map,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.a),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
__field0 = true;
|
||||
}
|
||||
__Field::__field1 => {
|
||||
if __field1 {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("b"),
|
||||
);
|
||||
}
|
||||
match _serde::de::MapAccess::next_value_seed(
|
||||
&mut __map,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.b),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
__field1 = true;
|
||||
}
|
||||
__Field::__field2 => {
|
||||
if __field2 {
|
||||
return _serde::__private::Err(
|
||||
<__A::Error as _serde::de::Error>::duplicate_field("c"),
|
||||
);
|
||||
}
|
||||
match _serde::de::MapAccess::next_value_seed(
|
||||
&mut __map,
|
||||
_serde::__private::de::InPlaceSeed(&mut self.place.c),
|
||||
) {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
__field2 = true;
|
||||
}
|
||||
_ => {
|
||||
let _ = match _serde::de::MapAccess::next_value::<
|
||||
_serde::de::IgnoredAny,
|
||||
>(&mut __map)
|
||||
{
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
if !__field0 {
|
||||
self.place.a = match _serde::__private::de::missing_field("a") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
};
|
||||
if !__field1 {
|
||||
self.place.b = match _serde::__private::de::missing_field("b") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
};
|
||||
if !__field2 {
|
||||
self.place.c = match _serde::__private::de::missing_field("c") {
|
||||
_serde::__private::Ok(__val) => __val,
|
||||
_serde::__private::Err(__err) => {
|
||||
return _serde::__private::Err(__err);
|
||||
}
|
||||
};
|
||||
};
|
||||
_serde::__private::Ok(())
|
||||
}
|
||||
}
|
||||
const FIELDS: &'static [&'static str] = &["a", "b", "c"];
|
||||
_serde::Deserializer::deserialize_struct(
|
||||
__deserializer,
|
||||
"DeNamedMap",
|
||||
FIELDS,
|
||||
__Visitor {
|
||||
place: __place,
|
||||
lifetime: _serde::__private::PhantomData,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct SerNamedMap<'a, 'b, A: 'a, B: 'b, C> {
|
||||
a: &'a A,
|
||||
b: &'b mut B,
|
||||
c: C,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct DeNamedMap<A, B, C> {
|
||||
a: A,
|
||||
b: B,
|
||||
c: C,
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user