@@ -12,7 +12,7 @@ use pyo3::{intern, PyTypeInfo};
1212
1313use speedate:: MicrosecondsPrecisionOverflowBehavior ;
1414
15- use crate :: errors:: { AsLocItem , ErrorType , ErrorTypeDefaults , InputValue , LocItem , ValError , ValResult } ;
15+ use crate :: errors:: { ErrorType , ErrorTypeDefaults , InputValue , LocItem , ValError , ValResult } ;
1616use crate :: tools:: { extract_i64, safe_repr} ;
1717use crate :: validators:: decimal:: { create_decimal, get_decimal_type} ;
1818use crate :: validators:: Exactness ;
@@ -92,21 +92,21 @@ macro_rules! extract_dict_items {
9292 } ;
9393}
9494
95- impl AsLocItem for PyAny {
96- fn as_loc_item ( & self ) -> LocItem {
97- if let Ok ( py_str) = self . downcast :: < PyString > ( ) {
95+ impl From < & PyAny > for LocItem {
96+ fn from ( py_any : & PyAny ) -> Self {
97+ if let Ok ( py_str) = py_any . downcast :: < PyString > ( ) {
9898 py_str. to_string_lossy ( ) . as_ref ( ) . into ( )
99- } else if let Some ( key_int) = extract_i64 ( self ) {
99+ } else if let Some ( key_int) = extract_i64 ( py_any ) {
100100 key_int. into ( )
101101 } else {
102- safe_repr ( self ) . to_string ( ) . into ( )
102+ safe_repr ( py_any ) . to_string ( ) . into ( )
103103 }
104104 }
105105}
106106
107- impl AsLocItem for & ' _ PyAny {
108- fn as_loc_item ( & self ) -> LocItem {
109- AsLocItem :: as_loc_item ( * self )
107+ impl From < PyAny > for LocItem {
108+ fn from ( py_any : PyAny ) -> Self {
109+ ( & py_any ) . into ( )
110110 }
111111}
112112
@@ -244,22 +244,6 @@ impl<'a> Input<'a> for PyAny {
244244 Err ( ValError :: new ( ErrorTypeDefaults :: StringType , self ) )
245245 }
246246
247- fn exact_str ( & ' a self ) -> ValResult < EitherString < ' a > > {
248- if let Ok ( py_str) = <PyString as PyTryFrom >:: try_from_exact ( self ) {
249- Ok ( EitherString :: Py ( py_str) )
250- } else {
251- Err ( ValError :: new ( ErrorTypeDefaults :: IntType , self ) )
252- }
253- }
254-
255- fn exact_int ( & ' a self ) -> ValResult < EitherInt < ' a > > {
256- if PyInt :: is_exact_type_of ( self ) {
257- Ok ( EitherInt :: Py ( self ) )
258- } else {
259- Err ( ValError :: new ( ErrorTypeDefaults :: IntType , self ) )
260- }
261- }
262-
263247 fn validate_bytes ( & ' a self , strict : bool ) -> ValResult < ValidationMatch < EitherBytes < ' a > > > {
264248 if let Ok ( py_bytes) = self . downcast_exact :: < PyBytes > ( ) {
265249 return Ok ( ValidationMatch :: exact ( py_bytes. into ( ) ) ) ;
@@ -347,6 +331,22 @@ impl<'a> Input<'a> for PyAny {
347331 Err ( ValError :: new ( ErrorTypeDefaults :: IntType , self ) )
348332 }
349333
334+ fn exact_int ( & ' a self ) -> ValResult < EitherInt < ' a > > {
335+ if PyInt :: is_exact_type_of ( self ) {
336+ Ok ( EitherInt :: Py ( self ) )
337+ } else {
338+ Err ( ValError :: new ( ErrorTypeDefaults :: IntType , self ) )
339+ }
340+ }
341+
342+ fn exact_str ( & ' a self ) -> ValResult < EitherString < ' a > > {
343+ if let Ok ( py_str) = <PyString as PyTryFrom >:: try_from_exact ( self ) {
344+ Ok ( EitherString :: Py ( py_str) )
345+ } else {
346+ Err ( ValError :: new ( ErrorTypeDefaults :: IntType , self ) )
347+ }
348+ }
349+
350350 fn validate_float ( & ' a self , strict : bool ) -> ValResult < ValidationMatch < EitherFloat < ' a > > > {
351351 if let Ok ( float) = self . downcast_exact :: < PyFloat > ( ) {
352352 return Ok ( ValidationMatch :: exact ( EitherFloat :: Py ( float) ) ) ;
0 commit comments