1
1
use std:: borrow:: Cow ;
2
+ use std:: sync:: Arc ;
2
3
3
4
use pyo3:: prelude:: * ;
4
5
use pyo3:: types:: { PyDict , PyString } ;
@@ -25,7 +26,7 @@ pub(super) struct SerField {
25
26
pub alias : Option < String > ,
26
27
pub alias_py : Option < Py < PyString > > ,
27
28
// None serializer means exclude
28
- pub serializer : Option < CombinedSerializer > ,
29
+ pub serializer : Option < Arc < CombinedSerializer > > ,
29
30
pub required : bool ,
30
31
pub serialize_by_alias : Option < bool > ,
31
32
pub serialization_exclude_if : Option < Py < PyAny > > ,
@@ -38,7 +39,7 @@ impl SerField {
38
39
py : Python ,
39
40
key_py : Py < PyString > ,
40
41
alias : Option < String > ,
41
- serializer : Option < CombinedSerializer > ,
42
+ serializer : Option < Arc < CombinedSerializer > > ,
42
43
required : bool ,
43
44
serialize_by_alias : Option < bool > ,
44
45
serialization_exclude_if : Option < Py < PyAny > > ,
@@ -113,7 +114,7 @@ pub struct GeneralFieldsSerializer {
113
114
fields : AHashMap < String , SerField > ,
114
115
computed_fields : Option < ComputedFields > ,
115
116
mode : FieldsMode ,
116
- extra_serializer : Option < Box < CombinedSerializer > > ,
117
+ extra_serializer : Option < Arc < CombinedSerializer > > ,
117
118
// isize because we look up filter via `.hash()` which returns an isize
118
119
filter : SchemaFilter < isize > ,
119
120
required_fields : usize ,
@@ -132,14 +133,14 @@ impl GeneralFieldsSerializer {
132
133
pub ( super ) fn new (
133
134
fields : AHashMap < String , SerField > ,
134
135
mode : FieldsMode ,
135
- extra_serializer : Option < CombinedSerializer > ,
136
+ extra_serializer : Option < Arc < CombinedSerializer > > ,
136
137
computed_fields : Option < ComputedFields > ,
137
138
) -> Self {
138
139
let required_fields = fields. values ( ) . filter ( |f| f. required ) . count ( ) ;
139
140
Self {
140
141
fields,
141
142
mode,
142
- extra_serializer : extra_serializer . map ( Box :: new ) ,
143
+ extra_serializer,
143
144
filter : SchemaFilter :: default ( ) ,
144
145
computed_fields,
145
146
required_fields,
0 commit comments