@@ -48,7 +48,7 @@ impl Instant {
48
48
let nanos = i128:: from_f64 ( result) . ok_or_else ( || {
49
49
TemporalError :: range ( ) . with_message ( "Duration added to instant exceeded valid range." )
50
50
} ) ?;
51
- Self :: new ( nanos)
51
+ Self :: try_new ( nanos)
52
52
}
53
53
54
54
// TODO: Add test for `diff_instant`.
@@ -150,7 +150,7 @@ impl Instant {
150
150
impl Instant {
151
151
/// Create a new validated `Instant`.
152
152
#[ inline]
153
- pub fn new ( epoch_nanoseconds : i128 ) -> TemporalResult < Self > {
153
+ pub fn try_new ( epoch_nanoseconds : i128 ) -> TemporalResult < Self > {
154
154
if !is_valid_epoch_nanos ( & epoch_nanoseconds) {
155
155
return Err ( TemporalError :: range ( )
156
156
. with_message ( "Instant nanoseconds are not within a valid epoch range." ) ) ;
@@ -230,7 +230,7 @@ impl Instant {
230
230
let resolved_options = ResolvedRoundingOptions :: from_instant_options ( options) ?;
231
231
232
232
let round_result = self . round_instant ( resolved_options) ?;
233
- Self :: new ( round_result)
233
+ Self :: try_new ( round_result)
234
234
}
235
235
236
236
/// Returns the `epochSeconds` value for this `Instant`.
@@ -335,17 +335,17 @@ mod tests {
335
335
// valid, i.e., a valid instant is within the range of an f64.
336
336
let max = NS_MAX_INSTANT ;
337
337
let min = NS_MIN_INSTANT ;
338
- let max_instant = Instant :: new ( max) . unwrap ( ) ;
339
- let min_instant = Instant :: new ( min) . unwrap ( ) ;
338
+ let max_instant = Instant :: try_new ( max) . unwrap ( ) ;
339
+ let min_instant = Instant :: try_new ( min) . unwrap ( ) ;
340
340
341
341
assert_eq ! ( max_instant. epoch_nanoseconds( ) , max. to_f64( ) . unwrap( ) ) ;
342
342
assert_eq ! ( min_instant. epoch_nanoseconds( ) , min. to_f64( ) . unwrap( ) ) ;
343
343
344
344
let max_plus_one = NS_MAX_INSTANT + 1 ;
345
345
let min_minus_one = NS_MIN_INSTANT - 1 ;
346
346
347
- assert ! ( Instant :: new ( max_plus_one) . is_err( ) ) ;
348
- assert ! ( Instant :: new ( min_minus_one) . is_err( ) ) ;
347
+ assert ! ( Instant :: try_new ( max_plus_one) . is_err( ) ) ;
348
+ assert ! ( Instant :: try_new ( min_minus_one) . is_err( ) ) ;
349
349
}
350
350
351
351
#[ test]
@@ -373,11 +373,11 @@ mod tests {
373
373
)
374
374
} ;
375
375
376
- let earlier = Instant :: new (
376
+ let earlier = Instant :: try_new (
377
377
217_178_610_123_456_789 , /* 1976-11-18T15:23:30.123456789Z */
378
378
)
379
379
. unwrap ( ) ;
380
- let later = Instant :: new (
380
+ let later = Instant :: try_new (
381
381
1_572_345_998_271_986_289 , /* 2019-10-29T10:46:38.271986289Z */
382
382
)
383
383
. unwrap ( ) ;
@@ -452,11 +452,11 @@ mod tests {
452
452
)
453
453
} ;
454
454
455
- let earlier = Instant :: new (
455
+ let earlier = Instant :: try_new (
456
456
217_178_610_123_456_789 , /* 1976-11-18T15:23:30.123456789Z */
457
457
)
458
458
. unwrap ( ) ;
459
- let later = Instant :: new (
459
+ let later = Instant :: try_new (
460
460
1_572_345_998_271_986_289 , /* 2019-10-29T10:46:38.271986289Z */
461
461
)
462
462
. unwrap ( ) ;
0 commit comments