@@ -14,6 +14,7 @@ use std::hash::Hasher;
1414use strum:: EnumMessage ;
1515
1616use super :: Input ;
17+ use crate :: errors:: ToErrorValue ;
1718use crate :: errors:: { ErrorType , ValError , ValResult } ;
1819use crate :: tools:: py_err;
1920
@@ -285,7 +286,7 @@ impl<'a> EitherDateTime<'a> {
285286 }
286287}
287288
288- pub fn bytes_as_date < ' a > ( input : & ' a impl Input < ' a > , bytes : & [ u8 ] ) -> ValResult < EitherDate < ' a > > {
289+ pub fn bytes_as_date < ' py > ( input : & ( impl Input < ' py > + ? Sized ) , bytes : & [ u8 ] ) -> ValResult < EitherDate < ' py > > {
289290 match Date :: parse_bytes ( bytes) {
290291 Ok ( date) => Ok ( date. into ( ) ) ,
291292 Err ( err) => Err ( ValError :: new (
@@ -298,11 +299,11 @@ pub fn bytes_as_date<'a>(input: &'a impl Input<'a>, bytes: &[u8]) -> ValResult<E
298299 }
299300}
300301
301- pub fn bytes_as_time < ' a > (
302- input : & ' a impl Input < ' a > ,
302+ pub fn bytes_as_time < ' py > (
303+ input : & ( impl Input < ' py > + ? Sized ) ,
303304 bytes : & [ u8 ] ,
304305 microseconds_overflow_behavior : MicrosecondsPrecisionOverflowBehavior ,
305- ) -> ValResult < EitherTime < ' a > > {
306+ ) -> ValResult < EitherTime < ' py > > {
306307 match Time :: parse_bytes_with_config (
307308 bytes,
308309 & TimeConfig {
@@ -321,11 +322,11 @@ pub fn bytes_as_time<'a>(
321322 }
322323}
323324
324- pub fn bytes_as_datetime < ' a , ' b > (
325- input : & ' a impl Input < ' a > ,
326- bytes : & ' b [ u8 ] ,
325+ pub fn bytes_as_datetime < ' py > (
326+ input : & ( impl Input < ' py > + ? Sized ) ,
327+ bytes : & [ u8 ] ,
327328 microseconds_overflow_behavior : MicrosecondsPrecisionOverflowBehavior ,
328- ) -> ValResult < EitherDateTime < ' a > > {
329+ ) -> ValResult < EitherDateTime < ' py > > {
329330 match DateTime :: parse_bytes_with_config (
330331 bytes,
331332 & TimeConfig {
@@ -344,11 +345,11 @@ pub fn bytes_as_datetime<'a, 'b>(
344345 }
345346}
346347
347- pub fn int_as_datetime < ' a > (
348- input : & ' a impl Input < ' a > ,
348+ pub fn int_as_datetime < ' py > (
349+ input : & ( impl Input < ' py > + ? Sized ) ,
349350 timestamp : i64 ,
350351 timestamp_microseconds : u32 ,
351- ) -> ValResult < EitherDateTime > {
352+ ) -> ValResult < EitherDateTime < ' py > > {
352353 match DateTime :: from_timestamp_with_config (
353354 timestamp,
354355 timestamp_microseconds,
@@ -382,7 +383,7 @@ macro_rules! nan_check {
382383 } ;
383384}
384385
385- pub fn float_as_datetime < ' a > ( input : & ' a impl Input < ' a > , timestamp : f64 ) -> ValResult < EitherDateTime > {
386+ pub fn float_as_datetime < ' py > ( input : & ( impl Input < ' py > + ? Sized ) , timestamp : f64 ) -> ValResult < EitherDateTime < ' py > > {
386387 nan_check ! ( input, timestamp, DatetimeParsing ) ;
387388 let microseconds = timestamp. fract ( ) . abs ( ) * 1_000_000.0 ;
388389 // checking for extra digits in microseconds is unreliable with large floats,
@@ -408,11 +409,11 @@ pub fn date_as_datetime<'py>(date: &Bound<'py, PyDate>) -> PyResult<EitherDateTi
408409
409410const MAX_U32 : i64 = u32:: MAX as i64 ;
410411
411- pub fn int_as_time < ' a > (
412- input : & ' a impl Input < ' a > ,
412+ pub fn int_as_time < ' py > (
413+ input : & ( impl Input < ' py > + ? Sized ) ,
413414 timestamp : i64 ,
414415 timestamp_microseconds : u32 ,
415- ) -> ValResult < EitherTime > {
416+ ) -> ValResult < EitherTime < ' py > > {
416417 let time_timestamp: u32 = match timestamp {
417418 t if t < 0_i64 => {
418419 return Err ( ValError :: new (
@@ -447,14 +448,14 @@ pub fn int_as_time<'a>(
447448 }
448449}
449450
450- pub fn float_as_time < ' a > ( input : & ' a impl Input < ' a > , timestamp : f64 ) -> ValResult < EitherTime > {
451+ pub fn float_as_time < ' py > ( input : & ( impl Input < ' py > + ? Sized ) , timestamp : f64 ) -> ValResult < EitherTime < ' py > > {
451452 nan_check ! ( input, timestamp, TimeParsing ) ;
452453 let microseconds = timestamp. fract ( ) . abs ( ) * 1_000_000.0 ;
453454 // round for same reason as above
454455 int_as_time ( input, timestamp. floor ( ) as i64 , microseconds. round ( ) as u32 )
455456}
456457
457- fn map_timedelta_err < ' a > ( input : & ' a impl Input < ' a > , err : ParseError ) -> ValError {
458+ fn map_timedelta_err ( input : impl ToErrorValue , err : ParseError ) -> ValError {
458459 ValError :: new (
459460 ErrorType :: TimeDeltaParsing {
460461 error : Cow :: Borrowed ( err. get_documentation ( ) . unwrap_or_default ( ) ) ,
@@ -464,11 +465,11 @@ fn map_timedelta_err<'a>(input: &'a impl Input<'a>, err: ParseError) -> ValError
464465 )
465466}
466467
467- pub fn bytes_as_timedelta < ' a , ' b > (
468- input : & ' a impl Input < ' a > ,
469- bytes : & ' b [ u8 ] ,
468+ pub fn bytes_as_timedelta < ' py > (
469+ input : & ( impl Input < ' py > + ? Sized ) ,
470+ bytes : & [ u8 ] ,
470471 microseconds_overflow_behavior : MicrosecondsPrecisionOverflowBehavior ,
471- ) -> ValResult < EitherTimedelta < ' a > > {
472+ ) -> ValResult < EitherTimedelta < ' py > > {
472473 match Duration :: parse_bytes_with_config (
473474 bytes,
474475 & TimeConfig {
@@ -481,7 +482,7 @@ pub fn bytes_as_timedelta<'a, 'b>(
481482 }
482483}
483484
484- pub fn int_as_duration < ' a > ( input : & ' a impl Input < ' a > , total_seconds : i64 ) -> ValResult < Duration > {
485+ pub fn int_as_duration ( input : impl ToErrorValue , total_seconds : i64 ) -> ValResult < Duration > {
485486 let positive = total_seconds >= 0 ;
486487 let total_seconds = total_seconds. unsigned_abs ( ) ;
487488 // we can safely unwrap here since we've guaranteed seconds and microseconds can't cause overflow
@@ -490,7 +491,7 @@ pub fn int_as_duration<'a>(input: &'a impl Input<'a>, total_seconds: i64) -> Val
490491 Duration :: new ( positive, days, seconds, 0 ) . map_err ( |err| map_timedelta_err ( input, err) )
491492}
492493
493- pub fn float_as_duration < ' a > ( input : & ' a impl Input < ' a > , total_seconds : f64 ) -> ValResult < Duration > {
494+ pub fn float_as_duration ( input : impl ToErrorValue , total_seconds : f64 ) -> ValResult < Duration > {
494495 nan_check ! ( input, total_seconds, TimeDeltaParsing ) ;
495496 let positive = total_seconds >= 0_f64 ;
496497 let total_seconds = total_seconds. abs ( ) ;
0 commit comments