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
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wreq
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.2.
|
|
4
|
+
version: 1.3.2.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SearchApi
|
|
@@ -30,6 +30,29 @@ files:
|
|
|
30
30
|
- VERSION
|
|
31
31
|
- build.rs
|
|
32
32
|
- crates/README.md
|
|
33
|
+
- crates/serde-magnus/Cargo.toml
|
|
34
|
+
- crates/serde-magnus/LICENSE
|
|
35
|
+
- crates/serde-magnus/README.md
|
|
36
|
+
- crates/serde-magnus/src/de/array_deserializer.rs
|
|
37
|
+
- crates/serde-magnus/src/de/array_enumerator.rs
|
|
38
|
+
- crates/serde-magnus/src/de/deserializer.rs
|
|
39
|
+
- crates/serde-magnus/src/de/enum_deserializer.rs
|
|
40
|
+
- crates/serde-magnus/src/de/hash_deserializer.rs
|
|
41
|
+
- crates/serde-magnus/src/de/mod.rs
|
|
42
|
+
- crates/serde-magnus/src/de/number_deserializer.rs
|
|
43
|
+
- crates/serde-magnus/src/de/variant_deserializer.rs
|
|
44
|
+
- crates/serde-magnus/src/error.rs
|
|
45
|
+
- crates/serde-magnus/src/lib.rs
|
|
46
|
+
- crates/serde-magnus/src/options.rs
|
|
47
|
+
- crates/serde-magnus/src/ser/enums.rs
|
|
48
|
+
- crates/serde-magnus/src/ser/map_serializer.rs
|
|
49
|
+
- crates/serde-magnus/src/ser/mod.rs
|
|
50
|
+
- crates/serde-magnus/src/ser/seq_serializer.rs
|
|
51
|
+
- crates/serde-magnus/src/ser/serializer.rs
|
|
52
|
+
- crates/serde-magnus/src/ser/struct_serializer.rs
|
|
53
|
+
- crates/serde-magnus/src/ser/struct_variant_serializer.rs
|
|
54
|
+
- crates/serde-magnus/src/ser/tuple_variant_serializer.rs
|
|
55
|
+
- crates/serde-magnus/src/tests.rs
|
|
33
56
|
- crates/wreq-util/.github/FUNDING.yml
|
|
34
57
|
- crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md
|
|
35
58
|
- crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md
|
|
@@ -128,25 +151,6 @@ files:
|
|
|
128
151
|
- src/macros.rs
|
|
129
152
|
- src/options.rs
|
|
130
153
|
- src/rt.rs
|
|
131
|
-
- src/serde.rs
|
|
132
|
-
- src/serde/de.rs
|
|
133
|
-
- src/serde/de/array_deserializer.rs
|
|
134
|
-
- src/serde/de/array_enumerator.rs
|
|
135
|
-
- src/serde/de/deserializer.rs
|
|
136
|
-
- src/serde/de/enum_deserializer.rs
|
|
137
|
-
- src/serde/de/hash_deserializer.rs
|
|
138
|
-
- src/serde/de/number_deserializer.rs
|
|
139
|
-
- src/serde/de/variant_deserializer.rs
|
|
140
|
-
- src/serde/error.rs
|
|
141
|
-
- src/serde/ser.rs
|
|
142
|
-
- src/serde/ser/enums.rs
|
|
143
|
-
- src/serde/ser/map_serializer.rs
|
|
144
|
-
- src/serde/ser/seq_serializer.rs
|
|
145
|
-
- src/serde/ser/serializer.rs
|
|
146
|
-
- src/serde/ser/struct_serializer.rs
|
|
147
|
-
- src/serde/ser/struct_variant_serializer.rs
|
|
148
|
-
- src/serde/ser/tuple_variant_serializer.rs
|
|
149
|
-
- src/serde/tests.rs
|
|
150
154
|
- src/tls.rs
|
|
151
155
|
- test/body_sender_test.rb
|
|
152
156
|
- test/client_cookie_test.rb
|
data/src/serde/de.rs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
mod array_deserializer;
|
|
2
|
-
mod array_enumerator;
|
|
3
|
-
mod deserializer;
|
|
4
|
-
mod enum_deserializer;
|
|
5
|
-
mod hash_deserializer;
|
|
6
|
-
mod number_deserializer;
|
|
7
|
-
mod variant_deserializer;
|
|
8
|
-
|
|
9
|
-
use ::serde::Deserialize;
|
|
10
|
-
use magnus::{Ruby, Value};
|
|
11
|
-
|
|
12
|
-
use super::Error;
|
|
13
|
-
use array_deserializer::ArrayDeserializer;
|
|
14
|
-
pub(super) use deserializer::Deserializer;
|
|
15
|
-
use deserializer::Mode;
|
|
16
|
-
use hash_deserializer::HashDeserializer;
|
|
17
|
-
use variant_deserializer::VariantDeserializer;
|
|
18
|
-
|
|
19
|
-
/// Deserialize one Ruby value using native Ruby data model semantics.
|
|
20
|
-
pub(super) fn deserialize_ruby<'de, Output>(ruby: &Ruby, value: Value) -> Result<Output, Error>
|
|
21
|
-
where
|
|
22
|
-
Output: Deserialize<'de>,
|
|
23
|
-
{
|
|
24
|
-
Output::deserialize(Deserializer::new_ruby(ruby, value))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// Deserialize one Ruby value using JSON-specific conversion rules.
|
|
28
|
-
pub(super) fn deserialize_json<'de, Output>(ruby: &Ruby, value: Value) -> Result<Output, Error>
|
|
29
|
-
where
|
|
30
|
-
Output: Deserialize<'de>,
|
|
31
|
-
{
|
|
32
|
-
Output::deserialize(Deserializer::new_json(ruby, value))
|
|
33
|
-
}
|
data/src/serde/error.rs
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
use std::fmt;
|
|
2
|
-
|
|
3
|
-
use magnus::error::ErrorType;
|
|
4
|
-
use serde_path_to_error::Path;
|
|
5
|
-
|
|
6
|
-
use crate::error::contextualize_magnus_error;
|
|
7
|
-
|
|
8
|
-
/// Error produced by the local Ruby and Serde bridge.
|
|
9
|
-
#[derive(Debug)]
|
|
10
|
-
pub(crate) enum Error {
|
|
11
|
-
Runtime(String),
|
|
12
|
-
Type(String),
|
|
13
|
-
DuplicateField(&'static str),
|
|
14
|
-
Ruby(magnus::Error),
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
impl Error {
|
|
18
|
-
/// Create a bridge error from a human-readable message.
|
|
19
|
-
pub(super) fn message(message: impl Into<String>) -> Self {
|
|
20
|
-
Self::Runtime(message.into())
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/// Create a type mismatch error.
|
|
24
|
-
pub(super) fn type_error(message: impl Into<String>) -> Self {
|
|
25
|
-
Self::Type(message.into())
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/// Convert this bridge error into the matching Ruby exception.
|
|
29
|
-
pub(super) fn into_magnus(self, ruby: &magnus::Ruby) -> magnus::Error {
|
|
30
|
-
match self {
|
|
31
|
-
Self::Runtime(message) => magnus::Error::new(ruby.exception_runtime_error(), message),
|
|
32
|
-
Self::Type(message) => magnus::Error::new(ruby.exception_type_error(), message),
|
|
33
|
-
Self::DuplicateField(field) => magnus::Error::new(
|
|
34
|
-
ruby.exception_runtime_error(),
|
|
35
|
-
format!("duplicate field `{field}`"),
|
|
36
|
-
),
|
|
37
|
-
Self::Ruby(error) => error,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/// Convert an option value error into Ruby's normal argument categories.
|
|
42
|
-
pub(super) fn into_option_magnus(
|
|
43
|
-
self,
|
|
44
|
-
ruby: &magnus::Ruby,
|
|
45
|
-
path: Option<&Path>,
|
|
46
|
-
) -> magnus::Error {
|
|
47
|
-
match self {
|
|
48
|
-
Self::Runtime(message) => magnus::Error::new(
|
|
49
|
-
ruby.exception_arg_error(),
|
|
50
|
-
contextualize_message(path, message),
|
|
51
|
-
),
|
|
52
|
-
Self::Type(message) => magnus::Error::new(
|
|
53
|
-
ruby.exception_type_error(),
|
|
54
|
-
contextualize_message(path, message),
|
|
55
|
-
),
|
|
56
|
-
Self::DuplicateField(field) => magnus::Error::new(
|
|
57
|
-
ruby.exception_arg_error(),
|
|
58
|
-
format!("duplicate option: :{field}"),
|
|
59
|
-
),
|
|
60
|
-
Self::Ruby(error) if error.is_kind_of(ruby.exception_range_error()) => {
|
|
61
|
-
magnus::Error::new(
|
|
62
|
-
ruby.exception_arg_error(),
|
|
63
|
-
magnus_error_message(&error, path),
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
Self::Ruby(error) => match path {
|
|
67
|
-
Some(path) => {
|
|
68
|
-
contextualize_magnus_error(error, format_args!("invalid value for :{path}"))
|
|
69
|
-
}
|
|
70
|
-
None => error,
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/// Prefix an error message when Serde identified the failing option path.
|
|
77
|
-
fn contextualize_message(path: Option<&Path>, message: String) -> String {
|
|
78
|
-
match path {
|
|
79
|
-
Some(path) => format!("invalid value for :{path}: {message}"),
|
|
80
|
-
None => message,
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/// Build the final Ruby error message without an intermediate context String.
|
|
85
|
-
fn magnus_error_message(error: &magnus::Error, path: Option<&Path>) -> String {
|
|
86
|
-
match (path, error.error_type()) {
|
|
87
|
-
(Some(path), ErrorType::Error(_, message)) => {
|
|
88
|
-
format!("invalid value for :{path}: {message}")
|
|
89
|
-
}
|
|
90
|
-
(Some(path), ErrorType::Exception(exception)) => {
|
|
91
|
-
format!("invalid value for :{path}: {exception}")
|
|
92
|
-
}
|
|
93
|
-
(Some(path), ErrorType::Jump(_)) => format!("invalid value for :{path}: {error}"),
|
|
94
|
-
(None, ErrorType::Error(_, message)) => message.as_ref().to_owned(),
|
|
95
|
-
(None, _) => error.to_string(),
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
impl fmt::Display for Error {
|
|
100
|
-
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
101
|
-
match self {
|
|
102
|
-
Self::Runtime(message) | Self::Type(message) => formatter.write_str(message),
|
|
103
|
-
Self::DuplicateField(field) => write!(formatter, "duplicate field `{field}`"),
|
|
104
|
-
Self::Ruby(error) => error.fmt(formatter),
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
impl std::error::Error for Error {}
|
|
110
|
-
|
|
111
|
-
impl ::serde::ser::Error for Error {
|
|
112
|
-
fn custom<T>(message: T) -> Self
|
|
113
|
-
where
|
|
114
|
-
T: fmt::Display,
|
|
115
|
-
{
|
|
116
|
-
Self::message(message.to_string())
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
impl ::serde::de::Error for Error {
|
|
121
|
-
fn custom<T>(message: T) -> Self
|
|
122
|
-
where
|
|
123
|
-
T: fmt::Display,
|
|
124
|
-
{
|
|
125
|
-
Self::message(message.to_string())
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
fn invalid_type(
|
|
129
|
-
unexpected: ::serde::de::Unexpected<'_>,
|
|
130
|
-
expected: &dyn ::serde::de::Expected,
|
|
131
|
-
) -> Self {
|
|
132
|
-
Self::type_error(format!(
|
|
133
|
-
"invalid type: expected {expected}, got {unexpected}"
|
|
134
|
-
))
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
fn duplicate_field(field: &'static str) -> Self {
|
|
138
|
-
Self::DuplicateField(field)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
impl From<magnus::Error> for Error {
|
|
143
|
-
fn from(error: magnus::Error) -> Self {
|
|
144
|
-
Self::Ruby(error)
|
|
145
|
-
}
|
|
146
|
-
}
|
data/src/serde/ser/enums.rs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
use magnus::{IntoValue, Ruby, Value};
|
|
2
|
-
|
|
3
|
-
use crate::serde::Error;
|
|
4
|
-
|
|
5
|
-
/// Wrap serialized enum data in the one-entry hash used by `serde_magnus`.
|
|
6
|
-
pub(super) fn nest(
|
|
7
|
-
ruby: &Ruby,
|
|
8
|
-
variant: &'static str,
|
|
9
|
-
data: impl IntoValue,
|
|
10
|
-
) -> Result<Value, Error> {
|
|
11
|
-
let hash = ruby.hash_new();
|
|
12
|
-
hash.aset(variant, data)?;
|
|
13
|
-
Ok(hash.into_value_with(ruby))
|
|
14
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
use ::serde::{
|
|
2
|
-
Serialize,
|
|
3
|
-
ser::{SerializeSeq, SerializeTuple, SerializeTupleStruct},
|
|
4
|
-
};
|
|
5
|
-
use magnus::{IntoValue, RArray, Ruby, Value};
|
|
6
|
-
|
|
7
|
-
use super::Serializer;
|
|
8
|
-
use crate::serde::Error;
|
|
9
|
-
|
|
10
|
-
/// Serde sequence serializer backed by a Ruby array.
|
|
11
|
-
pub(super) struct SeqSerializer<'ruby> {
|
|
12
|
-
ruby: &'ruby Ruby,
|
|
13
|
-
array: RArray,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
impl<'ruby> SeqSerializer<'ruby> {
|
|
17
|
-
/// Create a sequence serializer for an allocated Ruby array.
|
|
18
|
-
pub(super) fn new(ruby: &'ruby Ruby, array: RArray) -> Self {
|
|
19
|
-
Self { ruby, array }
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
impl SerializeSeq for SeqSerializer<'_> {
|
|
24
|
-
type Ok = Value;
|
|
25
|
-
type Error = Error;
|
|
26
|
-
|
|
27
|
-
fn serialize_element<T>(&mut self, element: &T) -> Result<(), Self::Error>
|
|
28
|
-
where
|
|
29
|
-
T: Serialize + ?Sized,
|
|
30
|
-
{
|
|
31
|
-
self.array
|
|
32
|
-
.push(element.serialize(Serializer::new(self.ruby))?)
|
|
33
|
-
.map_err(Into::into)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fn end(self) -> Result<Self::Ok, Self::Error> {
|
|
37
|
-
Ok(self.array.into_value_with(self.ruby))
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
impl SerializeTuple for SeqSerializer<'_> {
|
|
42
|
-
type Ok = Value;
|
|
43
|
-
type Error = Error;
|
|
44
|
-
|
|
45
|
-
fn serialize_element<T>(&mut self, element: &T) -> Result<(), Self::Error>
|
|
46
|
-
where
|
|
47
|
-
T: Serialize + ?Sized,
|
|
48
|
-
{
|
|
49
|
-
SerializeSeq::serialize_element(self, element)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
fn end(self) -> Result<Self::Ok, Self::Error> {
|
|
53
|
-
SerializeSeq::end(self)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
impl SerializeTupleStruct for SeqSerializer<'_> {
|
|
58
|
-
type Ok = Value;
|
|
59
|
-
type Error = Error;
|
|
60
|
-
|
|
61
|
-
fn serialize_field<T>(&mut self, field: &T) -> Result<(), Self::Error>
|
|
62
|
-
where
|
|
63
|
-
T: Serialize + ?Sized,
|
|
64
|
-
{
|
|
65
|
-
SerializeSeq::serialize_element(self, field)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
fn end(self) -> Result<Self::Ok, Self::Error> {
|
|
69
|
-
SerializeSeq::end(self)
|
|
70
|
-
}
|
|
71
|
-
}
|
data/src/serde/ser/serializer.rs
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
use ::serde::Serialize;
|
|
2
|
-
use magnus::{IntoValue, Ruby, Value};
|
|
3
|
-
|
|
4
|
-
use super::super::Error;
|
|
5
|
-
use super::{
|
|
6
|
-
enums::nest, map_serializer::MapSerializer, seq_serializer::SeqSerializer,
|
|
7
|
-
struct_serializer::StructSerializer, struct_variant_serializer::StructVariantSerializer,
|
|
8
|
-
tuple_variant_serializer::TupleVariantSerializer,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/// Implement primitive numeric serialization through Magnus's `IntoValue`.
|
|
12
|
-
macro_rules! impl_serialize_numbers {
|
|
13
|
-
($($method:ident => $type:ty),+ $(,)?) => {
|
|
14
|
-
$(
|
|
15
|
-
fn $method(self, value: $type) -> Result<Self::Ok, Self::Error> {
|
|
16
|
-
Ok(value.into_value_with(self.ruby))
|
|
17
|
-
}
|
|
18
|
-
)+
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/// Serde serializer that creates Ruby values.
|
|
23
|
-
pub(super) struct Serializer<'ruby> {
|
|
24
|
-
ruby: &'ruby Ruby,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
impl<'ruby> Serializer<'ruby> {
|
|
28
|
-
/// Create a serializer with upstream `serde_magnus` behavior.
|
|
29
|
-
pub(super) fn new(ruby: &'ruby Ruby) -> Self {
|
|
30
|
-
Self { ruby }
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
impl<'ruby> ::serde::Serializer for Serializer<'ruby> {
|
|
35
|
-
type Ok = Value;
|
|
36
|
-
type Error = Error;
|
|
37
|
-
|
|
38
|
-
type SerializeSeq = SeqSerializer<'ruby>;
|
|
39
|
-
type SerializeTuple = SeqSerializer<'ruby>;
|
|
40
|
-
type SerializeTupleStruct = SeqSerializer<'ruby>;
|
|
41
|
-
type SerializeTupleVariant = TupleVariantSerializer<'ruby>;
|
|
42
|
-
type SerializeMap = MapSerializer<'ruby>;
|
|
43
|
-
type SerializeStruct = StructSerializer<'ruby>;
|
|
44
|
-
type SerializeStructVariant = StructVariantSerializer<'ruby>;
|
|
45
|
-
|
|
46
|
-
fn serialize_bool(self, value: bool) -> Result<Self::Ok, Self::Error> {
|
|
47
|
-
Ok(value.into_value_with(self.ruby))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
impl_serialize_numbers! {
|
|
51
|
-
serialize_i8 => i8,
|
|
52
|
-
serialize_i16 => i16,
|
|
53
|
-
serialize_i32 => i32,
|
|
54
|
-
serialize_i64 => i64,
|
|
55
|
-
serialize_i128 => i128,
|
|
56
|
-
serialize_u8 => u8,
|
|
57
|
-
serialize_u16 => u16,
|
|
58
|
-
serialize_u32 => u32,
|
|
59
|
-
serialize_u64 => u64,
|
|
60
|
-
serialize_u128 => u128,
|
|
61
|
-
serialize_f32 => f32,
|
|
62
|
-
serialize_f64 => f64,
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
fn serialize_char(self, value: char) -> Result<Self::Ok, Self::Error> {
|
|
66
|
-
Ok(value.into_value_with(self.ruby))
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
fn serialize_str(self, value: &str) -> Result<Self::Ok, Self::Error> {
|
|
70
|
-
Ok(value.into_value_with(self.ruby))
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
fn serialize_bytes(self, value: &[u8]) -> Result<Self::Ok, Self::Error> {
|
|
74
|
-
Ok(self.ruby.str_from_slice(value).into_value_with(self.ruby))
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
|
|
78
|
-
self.serialize_unit()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
|
82
|
-
where
|
|
83
|
-
T: Serialize + ?Sized,
|
|
84
|
-
{
|
|
85
|
-
value.serialize(self)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
|
89
|
-
Ok(().into_value_with(self.ruby))
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Self::Error> {
|
|
93
|
-
self.serialize_unit()
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
fn serialize_unit_variant(
|
|
97
|
-
self,
|
|
98
|
-
_name: &'static str,
|
|
99
|
-
_index: u32,
|
|
100
|
-
variant: &'static str,
|
|
101
|
-
) -> Result<Self::Ok, Self::Error> {
|
|
102
|
-
self.serialize_str(variant)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
fn serialize_newtype_struct<T>(
|
|
106
|
-
self,
|
|
107
|
-
_name: &'static str,
|
|
108
|
-
value: &T,
|
|
109
|
-
) -> Result<Self::Ok, Self::Error>
|
|
110
|
-
where
|
|
111
|
-
T: Serialize + ?Sized,
|
|
112
|
-
{
|
|
113
|
-
value.serialize(self)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
fn serialize_newtype_variant<T>(
|
|
117
|
-
self,
|
|
118
|
-
_name: &'static str,
|
|
119
|
-
_index: u32,
|
|
120
|
-
variant: &'static str,
|
|
121
|
-
value: &T,
|
|
122
|
-
) -> Result<Self::Ok, Self::Error>
|
|
123
|
-
where
|
|
124
|
-
T: Serialize + ?Sized,
|
|
125
|
-
{
|
|
126
|
-
nest(
|
|
127
|
-
self.ruby,
|
|
128
|
-
variant,
|
|
129
|
-
value.serialize(Serializer::new(self.ruby))?,
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
|
|
134
|
-
Ok(SeqSerializer::new(
|
|
135
|
-
self.ruby,
|
|
136
|
-
self.ruby.ary_new_capa(len.unwrap_or(0)),
|
|
137
|
-
))
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> {
|
|
141
|
-
self.serialize_seq(Some(len))
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
fn serialize_tuple_struct(
|
|
145
|
-
self,
|
|
146
|
-
_name: &'static str,
|
|
147
|
-
len: usize,
|
|
148
|
-
) -> Result<Self::SerializeTupleStruct, Self::Error> {
|
|
149
|
-
self.serialize_seq(Some(len))
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
fn serialize_tuple_variant(
|
|
153
|
-
self,
|
|
154
|
-
_name: &'static str,
|
|
155
|
-
_index: u32,
|
|
156
|
-
variant: &'static str,
|
|
157
|
-
len: usize,
|
|
158
|
-
) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
|
159
|
-
Ok(TupleVariantSerializer::new(
|
|
160
|
-
self.ruby,
|
|
161
|
-
variant,
|
|
162
|
-
self.ruby.ary_new_capa(len),
|
|
163
|
-
))
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
|
167
|
-
Ok(MapSerializer::new(
|
|
168
|
-
self.ruby,
|
|
169
|
-
self.ruby.hash_new_capa(len.unwrap_or(0)),
|
|
170
|
-
))
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
fn serialize_struct(
|
|
174
|
-
self,
|
|
175
|
-
name: &'static str,
|
|
176
|
-
len: usize,
|
|
177
|
-
) -> Result<Self::SerializeStruct, Self::Error> {
|
|
178
|
-
Ok(StructSerializer::new(self.ruby, name, len))
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
fn serialize_struct_variant(
|
|
182
|
-
self,
|
|
183
|
-
_name: &'static str,
|
|
184
|
-
_index: u32,
|
|
185
|
-
variant: &'static str,
|
|
186
|
-
len: usize,
|
|
187
|
-
) -> Result<Self::SerializeStructVariant, Self::Error> {
|
|
188
|
-
Ok(StructVariantSerializer::new(
|
|
189
|
-
self.ruby,
|
|
190
|
-
variant,
|
|
191
|
-
self.ruby.hash_new_capa(len),
|
|
192
|
-
))
|
|
193
|
-
}
|
|
194
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
use ::serde::{Serialize, ser::SerializeStructVariant};
|
|
2
|
-
use magnus::{RHash, Ruby, Value};
|
|
3
|
-
|
|
4
|
-
use super::{Serializer, enums::nest};
|
|
5
|
-
use crate::serde::Error;
|
|
6
|
-
|
|
7
|
-
/// Serde struct-variant serializer backed by a Ruby hash.
|
|
8
|
-
pub(super) struct StructVariantSerializer<'ruby> {
|
|
9
|
-
ruby: &'ruby Ruby,
|
|
10
|
-
variant: &'static str,
|
|
11
|
-
hash: RHash,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
impl<'ruby> StructVariantSerializer<'ruby> {
|
|
15
|
-
/// Create a struct-variant serializer for an allocated Ruby hash.
|
|
16
|
-
pub(super) fn new(ruby: &'ruby Ruby, variant: &'static str, hash: RHash) -> Self {
|
|
17
|
-
Self {
|
|
18
|
-
ruby,
|
|
19
|
-
variant,
|
|
20
|
-
hash,
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
impl SerializeStructVariant for StructVariantSerializer<'_> {
|
|
26
|
-
type Ok = Value;
|
|
27
|
-
type Error = Error;
|
|
28
|
-
|
|
29
|
-
fn serialize_field<T>(&mut self, name: &'static str, value: &T) -> Result<(), Self::Error>
|
|
30
|
-
where
|
|
31
|
-
T: Serialize + ?Sized,
|
|
32
|
-
{
|
|
33
|
-
self.hash
|
|
34
|
-
.aset(
|
|
35
|
-
self.ruby.to_symbol(name),
|
|
36
|
-
value.serialize(Serializer::new(self.ruby))?,
|
|
37
|
-
)
|
|
38
|
-
.map_err(Into::into)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
fn end(self) -> Result<Self::Ok, Self::Error> {
|
|
42
|
-
nest(self.ruby, self.variant, self.hash)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
use ::serde::{Serialize, ser::SerializeTupleVariant};
|
|
2
|
-
use magnus::{RArray, Ruby, Value};
|
|
3
|
-
|
|
4
|
-
use super::{Serializer, enums::nest};
|
|
5
|
-
use crate::serde::Error;
|
|
6
|
-
|
|
7
|
-
/// Serde tuple-variant serializer backed by a Ruby array.
|
|
8
|
-
pub(super) struct TupleVariantSerializer<'ruby> {
|
|
9
|
-
ruby: &'ruby Ruby,
|
|
10
|
-
variant: &'static str,
|
|
11
|
-
array: RArray,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
impl<'ruby> TupleVariantSerializer<'ruby> {
|
|
15
|
-
/// Create a tuple-variant serializer for an allocated Ruby array.
|
|
16
|
-
pub(super) fn new(ruby: &'ruby Ruby, variant: &'static str, array: RArray) -> Self {
|
|
17
|
-
Self {
|
|
18
|
-
ruby,
|
|
19
|
-
variant,
|
|
20
|
-
array,
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
impl SerializeTupleVariant for TupleVariantSerializer<'_> {
|
|
26
|
-
type Ok = Value;
|
|
27
|
-
type Error = Error;
|
|
28
|
-
|
|
29
|
-
fn serialize_field<T>(&mut self, field: &T) -> Result<(), Self::Error>
|
|
30
|
-
where
|
|
31
|
-
T: Serialize + ?Sized,
|
|
32
|
-
{
|
|
33
|
-
self.array
|
|
34
|
-
.push(field.serialize(Serializer::new(self.ruby))?)
|
|
35
|
-
.map_err(Into::into)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fn end(self) -> Result<Self::Ok, Self::Error> {
|
|
39
|
-
nest(self.ruby, self.variant, self.array)
|
|
40
|
-
}
|
|
41
|
-
}
|
data/src/serde/ser.rs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
mod enums;
|
|
2
|
-
mod map_serializer;
|
|
3
|
-
mod seq_serializer;
|
|
4
|
-
mod serializer;
|
|
5
|
-
mod struct_serializer;
|
|
6
|
-
mod struct_variant_serializer;
|
|
7
|
-
mod tuple_variant_serializer;
|
|
8
|
-
|
|
9
|
-
use ::serde::Serialize;
|
|
10
|
-
use magnus::{Ruby, Value};
|
|
11
|
-
|
|
12
|
-
use super::Error;
|
|
13
|
-
use serializer::Serializer;
|
|
14
|
-
|
|
15
|
-
/// Serialize any Serde value into Ruby values.
|
|
16
|
-
pub(super) fn serialize(ruby: &Ruby, value: &(impl Serialize + ?Sized)) -> Result<Value, Error> {
|
|
17
|
-
value.serialize(Serializer::new(ruby))
|
|
18
|
-
}
|