forked from pydantic/pydantic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
any.rs
42 lines (35 loc) · 1.1 KB
/
any.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use pyo3::prelude::*;
use pyo3::types::PyDict;
use crate::errors::ValResult;
use crate::input::Input;
use crate::recursion_guard::RecursionGuard;
use super::{BuildContext, BuildValidator, CombinedValidator, Extra, Validator};
/// This might seem useless, but it's useful in DictValidator to avoid Option<Validator> a lot
#[derive(Debug, Clone)]
pub struct AnyValidator;
impl BuildValidator for AnyValidator {
const EXPECTED_TYPE: &'static str = "any";
fn build(
_schema: &PyDict,
_config: Option<&PyDict>,
_build_context: &mut BuildContext,
) -> PyResult<CombinedValidator> {
Ok(Self.into())
}
}
impl Validator for AnyValidator {
fn validate<'s, 'data>(
&'s self,
py: Python<'data>,
input: &'data impl Input<'data>,
_extra: &Extra,
_slots: &'data [CombinedValidator],
_recursion_guard: &'s mut RecursionGuard,
) -> ValResult<'data, PyObject> {
// Ok(input.clone().into_py(py))
Ok(input.to_object(py))
}
fn get_name(&self, _py: Python) -> String {
Self::EXPECTED_TYPE.to_string()
}
}