Skip to content

Commit a04e297

Browse files
committed
moving union const
1 parent e3aceeb commit a04e297

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub(crate) mod discriminator;
1+
pub(crate) mod union;

src/common/discriminator.rs renamed to src/common/union.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ impl PyGcTraverse for Discriminator {
3939
Ok(())
4040
}
4141
}
42+
43+
pub(crate) const SMALL_UNION_THRESHOLD: usize = 4;

src/serializers/type_serializers/union.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use smallvec::SmallVec;
66
use std::borrow::Cow;
77

88
use crate::build_tools::py_schema_err;
9-
use crate::common::discriminator::Discriminator;
9+
use crate::common::union::{Discriminator, SMALL_UNION_THRESHOLD};
1010
use crate::definitions::DefinitionsBuilder;
1111
use crate::lookup_key::LookupKey;
1212
use crate::serializers::type_serializers::py_err_se_err;
13-
use crate::tools::{SchemaDict, UNION_ERR_SMALLVEC_CAPACITY};
13+
use crate::tools::SchemaDict;
1414
use crate::PydanticSerializationUnexpectedValue;
1515

1616
use super::{
@@ -83,7 +83,7 @@ impl TypeSerializer for UnionSerializer {
8383
// try the serializers in left to right order with error_on fallback=true
8484
let mut new_extra = extra.clone();
8585
new_extra.check = SerCheck::Strict;
86-
let mut errors: SmallVec<[PyErr; UNION_ERR_SMALLVEC_CAPACITY]> = SmallVec::new();
86+
let mut errors: SmallVec<[PyErr; SMALL_UNION_THRESHOLD]> = SmallVec::new();
8787

8888
for comb_serializer in &self.choices {
8989
match comb_serializer.to_python(value, include, exclude, &new_extra) {
@@ -118,7 +118,7 @@ impl TypeSerializer for UnionSerializer {
118118
fn json_key<'a>(&self, key: &'a Bound<'_, PyAny>, extra: &Extra) -> PyResult<Cow<'a, str>> {
119119
let mut new_extra = extra.clone();
120120
new_extra.check = SerCheck::Strict;
121-
let mut errors: SmallVec<[PyErr; UNION_ERR_SMALLVEC_CAPACITY]> = SmallVec::new();
121+
let mut errors: SmallVec<[PyErr; SMALL_UNION_THRESHOLD]> = SmallVec::new();
122122

123123
for comb_serializer in &self.choices {
124124
match comb_serializer.json_key(key, &new_extra) {
@@ -161,7 +161,7 @@ impl TypeSerializer for UnionSerializer {
161161
let py = value.py();
162162
let mut new_extra = extra.clone();
163163
new_extra.check = SerCheck::Strict;
164-
let mut errors: SmallVec<[PyErr; UNION_ERR_SMALLVEC_CAPACITY]> = SmallVec::new();
164+
let mut errors: SmallVec<[PyErr; SMALL_UNION_THRESHOLD]> = SmallVec::new();
165165

166166
for comb_serializer in &self.choices {
167167
match comb_serializer.to_python(value, include, exclude, &new_extra) {

src/tools.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,3 @@ pub(crate) fn new_py_string<'py>(py: Python<'py>, s: &str, cache_str: StringCach
146146
pystring_fast_new(py, s, ascii_only)
147147
}
148148
}
149-
150-
pub(crate) const UNION_ERR_SMALLVEC_CAPACITY: usize = 4;

src/validators/union.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use smallvec::SmallVec;
99

1010
use crate::build_tools::py_schema_err;
1111
use crate::build_tools::{is_strict, schema_or_config};
12-
use crate::common::discriminator::Discriminator;
12+
use crate::common::union::{Discriminator, SMALL_UNION_THRESHOLD};
1313
use crate::errors::{ErrorType, ToErrorValue, ValError, ValLineError, ValResult};
1414
use crate::input::{BorrowInput, Input, ValidatedDict};
15-
use crate::tools::{SchemaDict, UNION_ERR_SMALLVEC_CAPACITY};
15+
use crate::tools::SchemaDict;
1616

1717
use super::custom_error::CustomError;
1818
use super::literal::LiteralLookup;
@@ -249,7 +249,7 @@ struct ChoiceLineErrors<'a> {
249249

250250
enum MaybeErrors<'a> {
251251
Custom(&'a CustomError),
252-
Errors(SmallVec<[ChoiceLineErrors<'a>; UNION_ERR_SMALLVEC_CAPACITY]>),
252+
Errors(SmallVec<[ChoiceLineErrors<'a>; SMALL_UNION_THRESHOLD]>),
253253
}
254254

255255
impl<'a> MaybeErrors<'a> {

0 commit comments

Comments
 (0)