wreq 1.3.2.3 → 1.3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Cargo.lock +24 -3
- data/Cargo.toml +5 -3
- data/Rakefile +9 -3
- data/VERSION +1 -1
- data/crates/README.md +1 -0
- data/crates/serde-magnus/Cargo.toml +29 -0
- data/crates/serde-magnus/LICENSE +19 -0
- data/crates/serde-magnus/README.md +147 -0
- data/{src/serde → crates/serde-magnus/src}/de/array_deserializer.rs +2 -2
- data/{src/serde → crates/serde-magnus/src}/de/array_enumerator.rs +1 -1
- data/{src/serde → crates/serde-magnus/src}/de/deserializer.rs +25 -31
- data/{src/serde → crates/serde-magnus/src}/de/enum_deserializer.rs +3 -3
- data/{src/serde → crates/serde-magnus/src}/de/hash_deserializer.rs +2 -2
- data/crates/serde-magnus/src/de/mod.rs +554 -0
- data/{src/serde → crates/serde-magnus/src}/de/number_deserializer.rs +2 -2
- data/{src/serde → crates/serde-magnus/src}/de/variant_deserializer.rs +11 -20
- data/crates/serde-magnus/src/error.rs +84 -0
- data/crates/serde-magnus/src/lib.rs +137 -0
- data/crates/serde-magnus/src/options.rs +151 -0
- data/crates/serde-magnus/src/ser/enums.rs +11 -0
- data/{src/serde → crates/serde-magnus/src}/ser/map_serializer.rs +2 -2
- data/crates/serde-magnus/src/ser/mod.rs +428 -0
- data/crates/serde-magnus/src/ser/seq_serializer.rs +68 -0
- data/crates/serde-magnus/src/ser/serializer.rs +220 -0
- data/{src/serde → crates/serde-magnus/src}/ser/struct_serializer.rs +4 -4
- data/crates/serde-magnus/src/ser/struct_variant_serializer.rs +45 -0
- data/crates/serde-magnus/src/ser/tuple_variant_serializer.rs +38 -0
- data/{src/serde → crates/serde-magnus/src}/tests.rs +19 -68
- data/src/client/body/json.rs +2 -1
- data/src/client/resp.rs +1 -1
- data/src/error.rs +3 -23
- data/src/lib.rs +0 -1
- data/src/options.rs +19 -17
- metadata +24 -20
- data/src/serde/de.rs +0 -33
- data/src/serde/error.rs +0 -146
- data/src/serde/ser/enums.rs +0 -14
- data/src/serde/ser/seq_serializer.rs +0 -71
- data/src/serde/ser/serializer.rs +0 -194
- data/src/serde/ser/struct_variant_serializer.rs +0 -44
- data/src/serde/ser/tuple_variant_serializer.rs +0 -41
- data/src/serde/ser.rs +0 -18
- data/src/serde.rs +0 -202
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ea9838e594215a15a3aa2abdb56551f10a9f689fe9b1c44c7c599f233685bc1
|
|
4
|
+
data.tar.gz: 0d92510b7a132fcfc2d945d28f913d51d67e3e78b5feae638d24a1f42e02606f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f48b4a8b7848ebb2a621e588374a0ab05bfeb92e729a1757cdc087f49d110d6af8d29ccdc5e9c172bedeb032e1cb3b347251490dc2f5fea66d8922f50c40ac29
|
|
7
|
+
data.tar.gz: ed40ac592c92890241360338112e1f5055440270a85f2bba6f10222587239170daca57949182603e4fdcc49b9ea905134f3a9ae93015d9d55f80ec34913b7ec0
|
data/Cargo.lock
CHANGED
|
@@ -763,7 +763,7 @@ dependencies = [
|
|
|
763
763
|
[[package]]
|
|
764
764
|
name = "netty"
|
|
765
765
|
version = "0.2.5"
|
|
766
|
-
source = "git+https://github.com/0x676e67/netty?branch=main#
|
|
766
|
+
source = "git+https://github.com/0x676e67/netty?branch=main#fd7884894c556fcdd4cfdb0b1932c3a6a60ab860"
|
|
767
767
|
dependencies = [
|
|
768
768
|
"bytes",
|
|
769
769
|
"futures-channel",
|
|
@@ -994,6 +994,16 @@ dependencies = [
|
|
|
994
994
|
"serde_derive",
|
|
995
995
|
]
|
|
996
996
|
|
|
997
|
+
[[package]]
|
|
998
|
+
name = "serde_bytes"
|
|
999
|
+
version = "0.11.19"
|
|
1000
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1001
|
+
checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8"
|
|
1002
|
+
dependencies = [
|
|
1003
|
+
"serde",
|
|
1004
|
+
"serde_core",
|
|
1005
|
+
]
|
|
1006
|
+
|
|
997
1007
|
[[package]]
|
|
998
1008
|
name = "serde_core"
|
|
999
1009
|
version = "1.0.229"
|
|
@@ -1052,6 +1062,18 @@ dependencies = [
|
|
|
1052
1062
|
"zmij",
|
|
1053
1063
|
]
|
|
1054
1064
|
|
|
1065
|
+
[[package]]
|
|
1066
|
+
name = "serde_magnus"
|
|
1067
|
+
version = "0.11.0"
|
|
1068
|
+
dependencies = [
|
|
1069
|
+
"indexmap",
|
|
1070
|
+
"magnus",
|
|
1071
|
+
"serde",
|
|
1072
|
+
"serde_bytes",
|
|
1073
|
+
"serde_ignored",
|
|
1074
|
+
"serde_path_to_error",
|
|
1075
|
+
]
|
|
1076
|
+
|
|
1055
1077
|
[[package]]
|
|
1056
1078
|
name = "serde_path_to_error"
|
|
1057
1079
|
version = "0.1.20"
|
|
@@ -1501,9 +1523,8 @@ dependencies = [
|
|
|
1501
1523
|
"rb-sys",
|
|
1502
1524
|
"rb-sys-env",
|
|
1503
1525
|
"serde",
|
|
1504
|
-
"serde_ignored",
|
|
1505
1526
|
"serde_json",
|
|
1506
|
-
"
|
|
1527
|
+
"serde_magnus",
|
|
1507
1528
|
"tokio",
|
|
1508
1529
|
"wreq",
|
|
1509
1530
|
"wreq-util",
|
data/Cargo.toml
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
name = "wreq-ruby"
|
|
3
3
|
description = "Ruby bindings for Wreq, HTTP client library in Rust."
|
|
4
4
|
authors = ["SearchApi <support@searchapi.io>"]
|
|
5
|
-
homepage = "https://github.com/SearchApi/wreq-ruby"
|
|
6
5
|
repository = "https://github.com/SearchApi/wreq-ruby"
|
|
7
6
|
edition = "2024"
|
|
8
7
|
version = "1.3.2"
|
|
9
8
|
rust-version = "1.100"
|
|
10
9
|
|
|
10
|
+
[workspace]
|
|
11
|
+
members = ["crates/serde-magnus"]
|
|
12
|
+
exclude = ["crates/wreq-util"]
|
|
13
|
+
|
|
11
14
|
[lib]
|
|
12
15
|
crate-type = ["cdylib"]
|
|
13
16
|
doc = false
|
|
@@ -36,12 +39,11 @@ wreq = { version = "0.16.1", default-features = false, features = [
|
|
|
36
39
|
] }
|
|
37
40
|
wreq-util = { version = "3.0.0-rc", features = ["emulation-compression"] }
|
|
38
41
|
serde = { version = "1.0.229", features = ["derive"] }
|
|
39
|
-
|
|
42
|
+
serde_magnus = { path = "crates/serde-magnus" }
|
|
40
43
|
serde_json = { version = "1.0.151", features = [
|
|
41
44
|
"arbitrary_precision",
|
|
42
45
|
"preserve_order",
|
|
43
46
|
] }
|
|
44
|
-
serde_path_to_error = "0.1.20"
|
|
45
47
|
indexmap = { version = "2.14.0", features = ["serde"] }
|
|
46
48
|
cookie = "0.18.1"
|
|
47
49
|
bytes = "1.12.1"
|
data/Rakefile
CHANGED
|
@@ -44,17 +44,23 @@ end
|
|
|
44
44
|
|
|
45
45
|
desc "Run Rust tests"
|
|
46
46
|
task :cargo_test do
|
|
47
|
-
|
|
47
|
+
test_env = {}
|
|
48
|
+
if RbConfig::CONFIG.fetch("host_os").start_with?("linux")
|
|
49
|
+
# Embedded Ruby tests need the active Ruby's shared library at startup.
|
|
50
|
+
test_env["LD_LIBRARY_PATH"] = [RbConfig::CONFIG.fetch("libdir"), ENV["LD_LIBRARY_PATH"]]
|
|
51
|
+
.compact.reject(&:empty?).join(File::PATH_SEPARATOR)
|
|
52
|
+
end
|
|
53
|
+
sh test_env, "cargo", "test", "--workspace", "--locked"
|
|
48
54
|
end
|
|
49
55
|
|
|
50
56
|
desc "Format Rust code"
|
|
51
57
|
task :fmt do
|
|
52
|
-
sh "cargo fmt"
|
|
58
|
+
sh "cargo fmt --all"
|
|
53
59
|
end
|
|
54
60
|
|
|
55
61
|
desc "Run Clippy linter"
|
|
56
62
|
task :lint do
|
|
57
|
-
sh "cargo clippy -- -D warnings"
|
|
63
|
+
sh "cargo clippy --workspace --locked -- -D warnings"
|
|
58
64
|
end
|
|
59
65
|
|
|
60
66
|
desc "Build native gem for platform (e.g., rake 'native[x86_64-linux]')"
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.3.2.
|
|
1
|
+
1.3.2.4
|
data/crates/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# Local Rust dependencies
|
|
2
2
|
|
|
3
|
+
- [`serde_magnus`](serde-magnus/) is based on OneSignal's `serde_magnus`. The root package uses it as a path dependency and workspace member so it shares the lockfile and runs in `bundle exec rake test`.
|
|
3
4
|
- [`wreq-util`](wreq-util/) is a local copy of [0x676e67/wreq-util](https://github.com/0x676e67/wreq-util). The root [`Cargo.toml`](../Cargo.toml) resolves it from `crates/wreq-util` through `[patch.crates-io]`.
|
|
4
5
|
|
|
5
6
|
When building or testing `wreq-util` on its own, use the Git dependency patches from the root manifest of the same branch. Cargo does not inherit those patches from the parent package.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "serde_magnus"
|
|
3
|
+
version = "0.11.0"
|
|
4
|
+
description = "Serde integration for Magnus"
|
|
5
|
+
edition = "2024"
|
|
6
|
+
rust-version = "1.98"
|
|
7
|
+
publish = false
|
|
8
|
+
authors = [
|
|
9
|
+
"Joe Wilm <joe@jwilm.com>",
|
|
10
|
+
"George Claghorn <georgeclaghorn@gmail.com>",
|
|
11
|
+
]
|
|
12
|
+
repository = "https://github.com/OneSignal/serde-magnus"
|
|
13
|
+
documentation = "https://docs.rs/serde_magnus"
|
|
14
|
+
license = "MIT"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
keywords = ["serde", "magnus", "ruby"]
|
|
17
|
+
categories = ["development-tools::ffi"]
|
|
18
|
+
|
|
19
|
+
[dependencies]
|
|
20
|
+
serde = "1.0"
|
|
21
|
+
magnus = { version = "0.9.0", features = ["bytes"] }
|
|
22
|
+
indexmap = "2.14.0"
|
|
23
|
+
serde_ignored = "0.1.14"
|
|
24
|
+
serde_path_to_error = "0.1.20"
|
|
25
|
+
|
|
26
|
+
[dev-dependencies]
|
|
27
|
+
serde = { version = "1.0", features = ["derive"] }
|
|
28
|
+
serde_bytes = "0.11"
|
|
29
|
+
magnus = { version = "0.9.0", features = ["embed"] }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright 2022 George Claghorn
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
+
so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# `serde_magnus`
|
|
2
|
+
|
|
3
|
+
`serde_magnus` converts between Rust and Ruby data structures using [Serde] and [Magnus].
|
|
4
|
+
|
|
5
|
+
[Serde]: https://github.com/serde-rs/serde
|
|
6
|
+
[Magnus]: https://github.com/matsadler/magnus
|
|
7
|
+
|
|
8
|
+
## Local maintenance
|
|
9
|
+
|
|
10
|
+
This crate is based on [OneSignal's serde_magnus 0.11.0 source][upstream]. It
|
|
11
|
+
uses the same Magnus 0.9 series and Rust 1.98 minimum as `wreq-ruby`.
|
|
12
|
+
|
|
13
|
+
### Local patches
|
|
14
|
+
|
|
15
|
+
- `src/de/` and `src/ser/` preserve arbitrary-size JSON integers in both
|
|
16
|
+
directions and support typed `i128` and `u128`. JSON input validates object keys,
|
|
17
|
+
finite floats, and container depth. The precision tests also cover the
|
|
18
|
+
private number token shared with `serde_json`.
|
|
19
|
+
- `src/options.rs` validates option names before converting values and attaches
|
|
20
|
+
the failing field path to Ruby exceptions.
|
|
21
|
+
- `src/error.rs` carries Serde errors until the conversion entry point can use
|
|
22
|
+
its Ruby handle. The deserializer and map serializer check iteration and map
|
|
23
|
+
state.
|
|
24
|
+
|
|
25
|
+
To sync, diff this directory against the pinned source tree, reapply the local
|
|
26
|
+
changes to the new upstream commit, and update the pin below. Run
|
|
27
|
+
`cargo test --locked -p serde_magnus` and `bundle exec rake test` from the
|
|
28
|
+
repository root. The Ruby tests in `test/json_precision_test.rb` and
|
|
29
|
+
`test/option_validation_test.rb` exercise the request, response, and option
|
|
30
|
+
entry points.
|
|
31
|
+
|
|
32
|
+
[upstream]: https://github.com/OneSignal/serde-magnus/tree/b84e35d03af9f84edf32e29c1fc022b4411ba9b9
|
|
33
|
+
|
|
34
|
+
## Upstream documentation
|
|
35
|
+
|
|
36
|
+
* [API documentation](https://docs.rs/serde_magnus)
|
|
37
|
+
* [Releases/changelog](https://github.com/OneSignal/serde-magnus/releases)
|
|
38
|
+
* [`serde_magnus` on crates.io](https://crates.io/crates/serde_magnus)
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
The [`serde_magnus::serialize`] function converts from a Rust type implementing the
|
|
43
|
+
[`serde::Serialize`] trait into a Ruby equivalent.
|
|
44
|
+
|
|
45
|
+
```rust
|
|
46
|
+
use serde::{Serialize, Deserialize};
|
|
47
|
+
use magnus::{eval, Ruby, Value};
|
|
48
|
+
use serde_magnus::serialize;
|
|
49
|
+
|
|
50
|
+
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
51
|
+
struct Post {
|
|
52
|
+
title: String,
|
|
53
|
+
content: String,
|
|
54
|
+
author: Author,
|
|
55
|
+
tags: Vec<String>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
59
|
+
struct Author {
|
|
60
|
+
name: String,
|
|
61
|
+
email_address: String
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let post = Post {
|
|
65
|
+
title: "Spring carnival planning update".into(),
|
|
66
|
+
content: "Here's what's new.".into(),
|
|
67
|
+
author: Author {
|
|
68
|
+
name: "Martha".into(),
|
|
69
|
+
email_address: "martha@example.com".into()
|
|
70
|
+
},
|
|
71
|
+
tags: vec![
|
|
72
|
+
"carnival".into(),
|
|
73
|
+
"update".into()
|
|
74
|
+
]
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
let ruby = Ruby::get().unwrap();
|
|
78
|
+
let post: Value = serialize(&ruby, &post)?;
|
|
79
|
+
|
|
80
|
+
assert!(eval!(
|
|
81
|
+
&ruby,
|
|
82
|
+
r#"
|
|
83
|
+
post == {
|
|
84
|
+
title: "Spring carnival planning update",
|
|
85
|
+
content: "Here's what's new.",
|
|
86
|
+
author: {
|
|
87
|
+
name: "Martha",
|
|
88
|
+
email_address: "martha@example.com"
|
|
89
|
+
},
|
|
90
|
+
tags: ["carnival", "update"]
|
|
91
|
+
}
|
|
92
|
+
"#,
|
|
93
|
+
post
|
|
94
|
+
)?);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
[`serde_magnus::deserialize`] converts from a Ruby value to a Rust type implementing
|
|
98
|
+
[`serde::Deserialize`].
|
|
99
|
+
|
|
100
|
+
```rust
|
|
101
|
+
use magnus::{RHash, Ruby};
|
|
102
|
+
use serde_magnus::deserialize;
|
|
103
|
+
|
|
104
|
+
let ruby = Ruby::get().unwrap();
|
|
105
|
+
let post: RHash = eval!(&ruby, r#"
|
|
106
|
+
{
|
|
107
|
+
title: "Spring carnival planning update",
|
|
108
|
+
content: "Here's what's new.",
|
|
109
|
+
author: {
|
|
110
|
+
name: "Martha",
|
|
111
|
+
email_address: "martha@example.com"
|
|
112
|
+
},
|
|
113
|
+
tags: ["carnival", "update"]
|
|
114
|
+
}
|
|
115
|
+
"#)?;
|
|
116
|
+
|
|
117
|
+
let post: Post = deserialize(&ruby, post)?;
|
|
118
|
+
|
|
119
|
+
assert_eq!(
|
|
120
|
+
Post {
|
|
121
|
+
title: "Spring carnival planning update".into(),
|
|
122
|
+
content: "Here's what's new.".into(),
|
|
123
|
+
author: Author {
|
|
124
|
+
name: "Martha".into(),
|
|
125
|
+
email_address: "martha@example.com".into(),
|
|
126
|
+
},
|
|
127
|
+
tags: vec![
|
|
128
|
+
"carnival".into(),
|
|
129
|
+
"update".into()
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
post
|
|
133
|
+
);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
[`serde_magnus::serialize`]: https://docs.rs/serde_magnus/latest/serde_magnus/fn.serialize.html
|
|
137
|
+
[`serde::Serialize`]: https://docs.rs/serde/latest/serde/trait.Serialize.html
|
|
138
|
+
[`serde_magnus::deserialize`]: https://docs.rs/serde_magnus/latest/serde_magnus/fn.deserialize.html
|
|
139
|
+
[`serde::Deserialize`]: https://docs.rs/serde/latest/serde/trait.Deserialize.html
|
|
140
|
+
|
|
141
|
+
## Requirements
|
|
142
|
+
|
|
143
|
+
The local crate shares the Rust and Ruby requirements of `wreq-ruby`.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
`serde_magnus` is released under the terms of the MIT License. See `LICENSE` for details.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
use ::serde::de::{DeserializeSeed, SeqAccess};
|
|
2
1
|
use magnus::{RArray, Ruby};
|
|
2
|
+
use serde::de::{DeserializeSeed, SeqAccess};
|
|
3
3
|
|
|
4
4
|
use super::{Deserializer, Mode, array_enumerator::ArrayEnumerator};
|
|
5
|
-
use crate::
|
|
5
|
+
use crate::error::Error;
|
|
6
6
|
|
|
7
7
|
/// Serde sequence access over a Ruby array.
|
|
8
8
|
pub(super) struct ArrayDeserializer<'ruby> {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
use ::serde::forward_to_deserialize_any;
|
|
2
1
|
use magnus::{
|
|
3
2
|
Fixnum, Float, Integer, RArray, RBignum, RHash, RString, Ruby, Symbol, Value,
|
|
4
3
|
value::{Qfalse, Qtrue, ReprValue},
|
|
5
4
|
};
|
|
5
|
+
use serde::forward_to_deserialize_any;
|
|
6
6
|
|
|
7
|
-
use super::super::{Error, MAX_JSON_NESTING};
|
|
8
7
|
use super::{
|
|
9
|
-
array_deserializer::ArrayDeserializer, enum_deserializer::EnumDeserializer,
|
|
8
|
+
array_deserializer::ArrayDeserializer, class_name, enum_deserializer::EnumDeserializer,
|
|
10
9
|
hash_deserializer::HashDeserializer, number_deserializer::NumberDeserializer,
|
|
11
10
|
};
|
|
12
|
-
use crate::
|
|
11
|
+
use crate::error::Error;
|
|
12
|
+
|
|
13
|
+
/// Maximum nesting of Ruby arrays and hashes in JSON input.
|
|
14
|
+
const MAX_JSON_NESTING: usize = 100;
|
|
13
15
|
|
|
14
16
|
/// Implement typed Serde integer entry points with Magnus's checked conversions.
|
|
15
17
|
macro_rules! impl_deserialize_integers {
|
|
@@ -17,7 +19,7 @@ macro_rules! impl_deserialize_integers {
|
|
|
17
19
|
$(
|
|
18
20
|
fn $method<Visitor>(self, visitor: Visitor) -> Result<Visitor::Value, Self::Error>
|
|
19
21
|
where
|
|
20
|
-
Visitor:
|
|
22
|
+
Visitor: serde::de::Visitor<'de>,
|
|
21
23
|
{
|
|
22
24
|
match Integer::from_value(self.value) {
|
|
23
25
|
Some(value) => visitor.$visit(value.$convert()?),
|
|
@@ -47,7 +49,7 @@ impl Mode {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/// Serde deserializer over Ruby values.
|
|
50
|
-
pub(
|
|
52
|
+
pub(crate) struct Deserializer<'ruby> {
|
|
51
53
|
ruby: &'ruby Ruby,
|
|
52
54
|
value: Value,
|
|
53
55
|
depth: usize,
|
|
@@ -56,12 +58,12 @@ pub(in crate::serde) struct Deserializer<'ruby> {
|
|
|
56
58
|
|
|
57
59
|
impl<'ruby> Deserializer<'ruby> {
|
|
58
60
|
/// Create a deserializer with native `serde_magnus` Ruby behavior.
|
|
59
|
-
pub(
|
|
61
|
+
pub(crate) fn new(ruby: &'ruby Ruby, value: Value) -> Self {
|
|
60
62
|
Self::with_mode(ruby, value, 0, Mode::Ruby)
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/// Create a deserializer that validates option keys without reading values.
|
|
64
|
-
pub(
|
|
66
|
+
pub(crate) fn new_option_keys(ruby: &'ruby Ruby, value: Value) -> Self {
|
|
65
67
|
Self::with_mode(ruby, value, 0, Mode::OptionKeys)
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -96,12 +98,12 @@ impl<'ruby> Deserializer<'ruby> {
|
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
impl<'de>
|
|
101
|
+
impl<'de> serde::Deserializer<'de> for Deserializer<'_> {
|
|
100
102
|
type Error = Error;
|
|
101
103
|
|
|
102
104
|
fn deserialize_any<Visitor>(self, visitor: Visitor) -> Result<Visitor::Value, Self::Error>
|
|
103
105
|
where
|
|
104
|
-
Visitor:
|
|
106
|
+
Visitor: serde::de::Visitor<'de>,
|
|
105
107
|
{
|
|
106
108
|
if self.value.is_nil() {
|
|
107
109
|
return visitor.visit_unit();
|
|
@@ -157,37 +159,34 @@ impl<'de> ::serde::Deserializer<'de> for Deserializer<'_> {
|
|
|
157
159
|
|
|
158
160
|
Err(Error::type_error(format!(
|
|
159
161
|
"can't deserialize {}",
|
|
160
|
-
|
|
161
|
-
unsafe { self.value.classname() }
|
|
162
|
+
class_name(self.value)
|
|
162
163
|
)))
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
fn deserialize_bytes<Visitor>(self, _visitor: Visitor) -> Result<Visitor::Value, Self::Error>
|
|
166
167
|
where
|
|
167
|
-
Visitor:
|
|
168
|
+
Visitor: serde::de::Visitor<'de>,
|
|
168
169
|
{
|
|
169
170
|
Err(Error::type_error("can't deserialize into byte slice"))
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
fn deserialize_byte_buf<Visitor>(self, visitor: Visitor) -> Result<Visitor::Value, Self::Error>
|
|
173
174
|
where
|
|
174
|
-
Visitor:
|
|
175
|
+
Visitor: serde::de::Visitor<'de>,
|
|
175
176
|
{
|
|
176
177
|
if let Some(string) = RString::from_value(self.value) {
|
|
177
|
-
|
|
178
|
-
visitor.visit_byte_buf(unsafe { string.as_slice() }.to_owned())
|
|
178
|
+
visitor.visit_byte_buf(string.to_bytes().into())
|
|
179
179
|
} else {
|
|
180
180
|
Err(Error::type_error(format!(
|
|
181
181
|
"no implicit conversion of {} to String",
|
|
182
|
-
|
|
183
|
-
unsafe { self.value.classname() }
|
|
182
|
+
class_name(self.value)
|
|
184
183
|
)))
|
|
185
184
|
}
|
|
186
185
|
}
|
|
187
186
|
|
|
188
187
|
fn deserialize_option<Visitor>(self, visitor: Visitor) -> Result<Visitor::Value, Self::Error>
|
|
189
188
|
where
|
|
190
|
-
Visitor:
|
|
189
|
+
Visitor: serde::de::Visitor<'de>,
|
|
191
190
|
{
|
|
192
191
|
if matches!(self.mode, Mode::OptionKeys) || self.value.is_nil() {
|
|
193
192
|
visitor.visit_none()
|
|
@@ -203,7 +202,7 @@ impl<'de> ::serde::Deserializer<'de> for Deserializer<'_> {
|
|
|
203
202
|
visitor: Visitor,
|
|
204
203
|
) -> Result<Visitor::Value, Self::Error>
|
|
205
204
|
where
|
|
206
|
-
Visitor:
|
|
205
|
+
Visitor: serde::de::Visitor<'de>,
|
|
207
206
|
{
|
|
208
207
|
if let Some(variant) = RString::from_value(self.value) {
|
|
209
208
|
return visitor.visit_enum(EnumDeserializer::new(
|
|
@@ -234,24 +233,19 @@ impl<'de> ::serde::Deserializer<'de> for Deserializer<'_> {
|
|
|
234
233
|
|
|
235
234
|
Err(Error::type_error(format!(
|
|
236
235
|
"can't deserialize {} to Enum",
|
|
237
|
-
|
|
238
|
-
unsafe { self.value.classname() }
|
|
236
|
+
class_name(self.value)
|
|
239
237
|
)))
|
|
240
238
|
}
|
|
241
239
|
|
|
242
240
|
fn deserialize_newtype_struct<Visitor>(
|
|
243
241
|
self,
|
|
244
|
-
|
|
242
|
+
_name: &'static str,
|
|
245
243
|
visitor: Visitor,
|
|
246
244
|
) -> Result<Visitor::Value, Self::Error>
|
|
247
245
|
where
|
|
248
|
-
Visitor:
|
|
246
|
+
Visitor: serde::de::Visitor<'de>,
|
|
249
247
|
{
|
|
250
|
-
|
|
251
|
-
visitor.visit_unit()
|
|
252
|
-
} else {
|
|
253
|
-
visitor.visit_newtype_struct(self)
|
|
254
|
-
}
|
|
248
|
+
visitor.visit_newtype_struct(self)
|
|
255
249
|
}
|
|
256
250
|
|
|
257
251
|
fn deserialize_ignored_any<Visitor>(
|
|
@@ -259,7 +253,7 @@ impl<'de> ::serde::Deserializer<'de> for Deserializer<'_> {
|
|
|
259
253
|
visitor: Visitor,
|
|
260
254
|
) -> Result<Visitor::Value, Self::Error>
|
|
261
255
|
where
|
|
262
|
-
Visitor:
|
|
256
|
+
Visitor: serde::de::Visitor<'de>,
|
|
263
257
|
{
|
|
264
258
|
visitor.visit_unit()
|
|
265
259
|
}
|
|
@@ -269,7 +263,7 @@ impl<'de> ::serde::Deserializer<'de> for Deserializer<'_> {
|
|
|
269
263
|
visitor: Visitor,
|
|
270
264
|
) -> Result<Visitor::Value, Self::Error>
|
|
271
265
|
where
|
|
272
|
-
Visitor:
|
|
266
|
+
Visitor: serde::de::Visitor<'de>,
|
|
273
267
|
{
|
|
274
268
|
if matches!(self.mode, Mode::OptionKeys) {
|
|
275
269
|
if let Some(value) = RString::from_value(self.value) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
use ::serde::de::{DeserializeSeed, EnumAccess, value::StringDeserializer};
|
|
2
1
|
use magnus::{Ruby, Value};
|
|
2
|
+
use serde::de::{DeserializeSeed, EnumAccess, IntoDeserializer};
|
|
3
3
|
|
|
4
4
|
use super::{Mode, VariantDeserializer};
|
|
5
|
-
use crate::
|
|
5
|
+
use crate::error::Error;
|
|
6
6
|
|
|
7
7
|
/// Serde enum access over a Ruby string or one-entry hash.
|
|
8
8
|
pub(super) struct EnumDeserializer<'ruby> {
|
|
@@ -41,7 +41,7 @@ impl<'ruby, 'de> EnumAccess<'de> for EnumDeserializer<'ruby> {
|
|
|
41
41
|
Seed: DeserializeSeed<'de>,
|
|
42
42
|
{
|
|
43
43
|
let variant = VariantDeserializer::new(self.ruby, self.value, self.depth, self.mode);
|
|
44
|
-
seed.deserialize(
|
|
44
|
+
seed.deserialize(self.variant.into_deserializer())
|
|
45
45
|
.map(|value| (value, variant))
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
use std::iter::Peekable;
|
|
2
2
|
|
|
3
|
-
use ::serde::de::{DeserializeSeed, MapAccess};
|
|
4
3
|
use magnus::{RHash, RString, Ruby, Symbol, Value, r_hash::ForEach};
|
|
4
|
+
use serde::de::{DeserializeSeed, MapAccess};
|
|
5
5
|
|
|
6
6
|
use super::{Deserializer, Mode, array_enumerator::ArrayEnumerator};
|
|
7
|
-
use crate::
|
|
7
|
+
use crate::error::Error;
|
|
8
8
|
|
|
9
9
|
/// Serde map access over a Ruby hash.
|
|
10
10
|
pub(super) struct HashDeserializer<'ruby> {
|