Skip to content

Commit f3a304a

Browse files
committed
figure out issue with borrowed serializer
1 parent 7ea0d64 commit f3a304a

File tree

1 file changed

+20
-23
lines changed
  • src/serializers/type_serializers

1 file changed

+20
-23
lines changed

src/serializers/type_serializers/union.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use pyo3::prelude::*;
44
use pyo3::types::{PyDict, PyList, PyTuple};
55
use smallvec::SmallVec;
66
use std::borrow::Cow;
7-
use std::sync::Arc;
87

98
use crate::build_tools::py_schema_err;
109
use crate::common::union::{Discriminator, SMALL_UNION_THRESHOLD};
@@ -127,7 +126,7 @@ fn tagged_union_serialize<S>(
127126
// `S` is intermediate state which can be passed on to the finalizer
128127
mut selector: impl FnMut(&CombinedSerializer, &Extra) -> PyResult<S>,
129128
extra: &Extra,
130-
choices: &Vec<CombinedSerializer>,
129+
choices: &[CombinedSerializer],
131130
retry_with_lax_check: bool,
132131
) -> Option<S> {
133132
let mut new_extra = extra.clone();
@@ -138,12 +137,12 @@ fn tagged_union_serialize<S>(
138137
if let Some(&serializer_index) = lookup.get(&tag_str) {
139138
let selected_serializer = &choices[serializer_index];
140139

141-
match selector(&selected_serializer, &new_extra) {
140+
match selector(selected_serializer, &new_extra) {
142141
Ok(v) => return Some(v),
143142
Err(_) => {
144143
if retry_with_lax_check {
145144
new_extra.check = SerCheck::Lax;
146-
if let Ok(v) = selector(&selected_serializer, &new_extra) {
145+
if let Ok(v) = selector(selected_serializer, &new_extra) {
147146
return Some(v);
148147
}
149148
}
@@ -337,35 +336,33 @@ impl TypeSerializer for TaggedUnionSerializer {
337336
comb_serializer.to_python(value, include, exclude, new_extra)
338337
};
339338

340-
tagged_union_serialize(
339+
if let Some(v) = tagged_union_serialize(
341340
None,
342341
&self.lookup,
343342
serde_selector,
344343
extra,
345344
&self.choices,
346345
self.retry_with_lax_check(),
347-
)
348-
.map_or_else(
349-
|| {
350-
union_serialize(
351-
serde_selector,
352-
|v| {
353-
infer_serialize(
354-
v.as_ref().map_or(value, |v| v.bind(value.py())),
355-
serializer,
356-
None,
357-
None,
358-
extra,
359-
)
360-
},
346+
) {
347+
return infer_serialize(v.bind(value.py()), serializer, None, None, extra);
348+
}
349+
350+
union_serialize(
351+
serde_selector,
352+
|v| {
353+
infer_serialize(
354+
v.as_ref().map_or(value, |v| v.bind(value.py())),
355+
serializer,
356+
None,
357+
None,
361358
extra,
362-
&self.choices,
363-
self.retry_with_lax_check(),
364359
)
365-
.map_err(|err| serde::ser::Error::custom(err.to_string()))?
366360
},
367-
|v| infer_serialize(v.bind(value.py()), serializer, None, None, extra),
361+
extra,
362+
&self.choices,
363+
self.retry_with_lax_check(),
368364
)
365+
.map_err(|err| serde::ser::Error::custom(err.to_string()))?
369366
}
370367

371368
fn get_name(&self) -> &str {

0 commit comments

Comments
 (0)