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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +24 -3
  3. data/Cargo.toml +5 -3
  4. data/Rakefile +9 -3
  5. data/VERSION +1 -1
  6. data/crates/README.md +1 -0
  7. data/crates/serde-magnus/Cargo.toml +29 -0
  8. data/crates/serde-magnus/LICENSE +19 -0
  9. data/crates/serde-magnus/README.md +147 -0
  10. data/{src/serde → crates/serde-magnus/src}/de/array_deserializer.rs +2 -2
  11. data/{src/serde → crates/serde-magnus/src}/de/array_enumerator.rs +1 -1
  12. data/{src/serde → crates/serde-magnus/src}/de/deserializer.rs +25 -31
  13. data/{src/serde → crates/serde-magnus/src}/de/enum_deserializer.rs +3 -3
  14. data/{src/serde → crates/serde-magnus/src}/de/hash_deserializer.rs +2 -2
  15. data/crates/serde-magnus/src/de/mod.rs +554 -0
  16. data/{src/serde → crates/serde-magnus/src}/de/number_deserializer.rs +2 -2
  17. data/{src/serde → crates/serde-magnus/src}/de/variant_deserializer.rs +11 -20
  18. data/crates/serde-magnus/src/error.rs +84 -0
  19. data/crates/serde-magnus/src/lib.rs +137 -0
  20. data/crates/serde-magnus/src/options.rs +151 -0
  21. data/crates/serde-magnus/src/ser/enums.rs +11 -0
  22. data/{src/serde → crates/serde-magnus/src}/ser/map_serializer.rs +2 -2
  23. data/crates/serde-magnus/src/ser/mod.rs +428 -0
  24. data/crates/serde-magnus/src/ser/seq_serializer.rs +68 -0
  25. data/crates/serde-magnus/src/ser/serializer.rs +220 -0
  26. data/{src/serde → crates/serde-magnus/src}/ser/struct_serializer.rs +4 -4
  27. data/crates/serde-magnus/src/ser/struct_variant_serializer.rs +45 -0
  28. data/crates/serde-magnus/src/ser/tuple_variant_serializer.rs +38 -0
  29. data/{src/serde → crates/serde-magnus/src}/tests.rs +19 -68
  30. data/src/client/body/json.rs +2 -1
  31. data/src/client/resp.rs +1 -1
  32. data/src/error.rs +3 -23
  33. data/src/lib.rs +0 -1
  34. data/src/options.rs +19 -17
  35. metadata +24 -20
  36. data/src/serde/de.rs +0 -33
  37. data/src/serde/error.rs +0 -146
  38. data/src/serde/ser/enums.rs +0 -14
  39. data/src/serde/ser/seq_serializer.rs +0 -71
  40. data/src/serde/ser/serializer.rs +0 -194
  41. data/src/serde/ser/struct_variant_serializer.rs +0 -44
  42. data/src/serde/ser/tuple_variant_serializer.rs +0 -41
  43. data/src/serde/ser.rs +0 -18
  44. data/src/serde.rs +0 -202
data/src/serde.rs DELETED
@@ -1,202 +0,0 @@
1
- /*
2
- Copyright 2022 George Claghorn
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
- of the Software, and to permit persons to whom the Software is furnished to do
9
- so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- SOFTWARE.
21
- */
22
-
23
- //! Serde integration for Magnus with JSON-specific conversion behavior.
24
- //!
25
- //! This module is adapted from `serde_magnus` 0.11.0 and retains its generic
26
- //! Ruby serialization and deserialization surface. Local changes add a JSON
27
- //! mode with arbitrary-size integer support, finite-float and object-key
28
- //! validation, insertion-order preservation, and bounded container nesting.
29
- //! The bridge also avoids the upstream `Ruby::get().unwrap()` error path,
30
- //! checks iterator and map state explicitly, reports unknown option fields and
31
- //! conversion paths, and supports `i128` and `u128` in both directions for
32
- //! typed Rust values.
33
- #![allow(unsafe_code)]
34
-
35
- mod de;
36
- mod error;
37
- mod ser;
38
- #[cfg(test)]
39
- mod tests;
40
-
41
- use ::serde::{Deserialize, Serialize, de::DeserializeOwned};
42
- use indexmap::IndexSet;
43
- use magnus::{IntoValue, Ruby, TryConvert};
44
- use serde_ignored::Path;
45
- use serde_path_to_error::{Deserializer as PathDeserializer, Track};
46
-
47
- use crate::error::argument_error;
48
-
49
- pub(super) use error::Error;
50
-
51
- /// Private map key used to carry arbitrary-precision numbers through Serde.
52
- ///
53
- /// This mirrors the representation used by `serde_json` when its
54
- /// `arbitrary_precision` feature is enabled. The precision tests protect this
55
- /// integration point when `serde_json` is updated.
56
- pub(super) const JSON_NUMBER_TOKEN: &str = "$serde_json::private::Number";
57
-
58
- /// Maximum nesting accepted while converting a Ruby request value.
59
- pub(super) const MAX_JSON_NESTING: usize = 100;
60
-
61
- /// Deserialize a Ruby value using native Ruby data model semantics.
62
- ///
63
- /// This preserves the public conversion behavior provided by the upstream
64
- /// `serde_magnus::deserialize` function. JSON callers should use
65
- /// [`deserialize_json`] when arbitrary-size integer precision is required.
66
- ///
67
- /// # Errors
68
- ///
69
- /// Returns the Ruby exception produced when the input cannot be represented by
70
- /// `Output`.
71
- #[allow(dead_code)] // Retained as part of the upstream-compatible Serde surface.
72
- pub(crate) fn deserialize_ruby<'de, Input, Output>(
73
- ruby: &Ruby,
74
- input: Input,
75
- ) -> Result<Output, magnus::Error>
76
- where
77
- Input: IntoValue,
78
- Output: Deserialize<'de>,
79
- {
80
- de::deserialize_ruby(ruby, input.into_value_with(ruby)).map_err(|error| error.into_magnus(ruby))
81
- }
82
-
83
- /// Serialize any Serde value into a Ruby value.
84
- ///
85
- /// This preserves the public conversion behavior provided by the upstream
86
- /// `serde_magnus::serialize` function.
87
- ///
88
- /// # Errors
89
- ///
90
- /// Returns the Ruby exception produced while creating or converting the output
91
- /// value.
92
- pub(crate) fn serialize<Input, Output>(ruby: &Ruby, input: &Input) -> Result<Output, magnus::Error>
93
- where
94
- Input: Serialize + ?Sized,
95
- Output: TryConvert,
96
- {
97
- let value = ser::serialize(ruby, input).map_err(|error| error.into_magnus(ruby))?;
98
- Output::try_convert(value)
99
- }
100
-
101
- /// Deserialize a Ruby value using JSON-specific conversion rules.
102
- ///
103
- /// Unlike [`deserialize_ruby`], this preserves arbitrary-size integers and
104
- /// rejects non-finite floats, unsupported object keys, and excessive nesting.
105
- ///
106
- /// # Errors
107
- ///
108
- /// Returns the Ruby exception produced when the input cannot be represented by
109
- /// `Output`.
110
- pub(crate) fn deserialize_json<'de, Input, Output>(
111
- ruby: &Ruby,
112
- input: Input,
113
- ) -> Result<Output, magnus::Error>
114
- where
115
- Input: IntoValue,
116
- Output: Deserialize<'de>,
117
- {
118
- de::deserialize_json(ruby, input.into_value_with(ruby)).map_err(|error| error.into_magnus(ruby))
119
- }
120
-
121
- /// Validate Ruby option keys without inspecting their values.
122
- ///
123
- /// The derived struct is the only list of accepted keys. Every option field is
124
- /// optional, so this pass can collect unknown keys and duplicates without
125
- /// converting or retaining any Ruby value.
126
- ///
127
- /// # Errors
128
- ///
129
- /// Returns `ArgumentError` for unknown or duplicate keys and `TypeError` for
130
- /// keys that are neither Ruby Symbols nor Strings.
131
- pub(crate) fn validate_option_keys<Input, Output>(
132
- ruby: &Ruby,
133
- input: Input,
134
- ) -> Result<(), magnus::Error>
135
- where
136
- Input: IntoValue,
137
- Output: DeserializeOwned,
138
- {
139
- let value: magnus::Value = input.into_value_with(ruby);
140
- let mut unknown = IndexSet::new();
141
- {
142
- let mut callback = |path: Path<'_>| {
143
- if let Path::Map { key, .. } = path {
144
- unknown.insert(key);
145
- }
146
- };
147
- serde_ignored::deserialize::<_, _, Output>(
148
- de::Deserializer::new_option_keys(ruby, value),
149
- &mut callback,
150
- )
151
- .map_err(|error| error.into_option_magnus(ruby, None))?;
152
- }
153
-
154
- if unknown.is_empty() {
155
- return Ok(());
156
- }
157
-
158
- let label = if unknown.len() == 1 {
159
- "unknown option"
160
- } else {
161
- "unknown options"
162
- };
163
- let mut message = String::from(label);
164
- message.push(':');
165
- for (index, name) in unknown.into_iter().enumerate() {
166
- if index > 0 {
167
- message.push(',');
168
- }
169
- message.push(' ');
170
- message.push(':');
171
- message.push_str(&name);
172
- }
173
-
174
- Err(argument_error(ruby, message))
175
- }
176
-
177
- /// Deserialize validated Ruby options and retain the failing field path.
178
- ///
179
- /// # Errors
180
- ///
181
- /// Returns the Ruby conversion error with the failing option path attached.
182
- pub(crate) fn deserialize_options<Input, Output>(
183
- ruby: &Ruby,
184
- input: Input,
185
- ) -> Result<Output, magnus::Error>
186
- where
187
- Input: IntoValue,
188
- Output: DeserializeOwned,
189
- {
190
- let value = input.into_value_with(ruby);
191
- let mut track = Track::new();
192
- let result = Output::deserialize(PathDeserializer::new(
193
- de::Deserializer::new_ruby(ruby, value),
194
- &mut track,
195
- ));
196
-
197
- result.map_err(|error| {
198
- let path = track.path();
199
- let path = path.iter().next().is_some().then_some(&path);
200
- error.into_option_magnus(ruby, path)
201
- })
202
- }