@@ -236,31 +236,17 @@ fn test_try() {
236
236
237
237
#[ test]
238
238
fn test_result_as_deref ( ) {
239
- // &Result<T: Deref, E>::Ok(T).as_deref_ok () ->
239
+ // &Result<T: Deref, E>::Ok(T).as_deref () ->
240
240
// Result<&T::Deref::Target, &E>::Ok(&*T)
241
241
let ref_ok = & Result :: Ok :: < & i32 , u8 > ( & 42 ) ;
242
242
let expected_result = Result :: Ok :: < & i32 , & u8 > ( & 42 ) ;
243
- assert_eq ! ( ref_ok. as_deref_ok( ) , expected_result) ;
244
-
245
- let ref_ok = & Result :: Ok :: < String , u32 > ( String :: from ( "a result" ) ) ;
246
- let expected_result = Result :: Ok :: < & str , & u32 > ( "a result" ) ;
247
- assert_eq ! ( ref_ok. as_deref_ok( ) , expected_result) ;
248
-
249
- let ref_ok = & Result :: Ok :: < Vec < i32 > , u32 > ( vec ! [ 1 , 2 , 3 , 4 , 5 ] ) ;
250
- let expected_result = Result :: Ok :: < & [ i32 ] , & u32 > ( [ 1 , 2 , 3 , 4 , 5 ] . as_slice ( ) ) ;
251
- assert_eq ! ( ref_ok. as_deref_ok( ) , expected_result) ;
252
-
253
- // &Result<T: Deref, E: Deref>::Ok(T).as_deref() ->
254
- // Result<&T::Deref::Target, &E::Deref::Target>::Ok(&*T)
255
- let ref_ok = & Result :: Ok :: < & i32 , & u8 > ( & 42 ) ;
256
- let expected_result = Result :: Ok :: < & i32 , & u8 > ( & 42 ) ;
257
243
assert_eq ! ( ref_ok. as_deref( ) , expected_result) ;
258
244
259
- let ref_ok = & Result :: Ok :: < String , & u32 > ( String :: from ( "a result" ) ) ;
245
+ let ref_ok = & Result :: Ok :: < String , u32 > ( String :: from ( "a result" ) ) ;
260
246
let expected_result = Result :: Ok :: < & str , & u32 > ( "a result" ) ;
261
247
assert_eq ! ( ref_ok. as_deref( ) , expected_result) ;
262
248
263
- let ref_ok = & Result :: Ok :: < Vec < i32 > , & u32 > ( vec ! [ 1 , 2 , 3 , 4 , 5 ] ) ;
249
+ let ref_ok = & Result :: Ok :: < Vec < i32 > , u32 > ( vec ! [ 1 , 2 , 3 , 4 , 5 ] ) ;
264
250
let expected_result = Result :: Ok :: < & [ i32 ] , & u32 > ( [ 1 , 2 , 3 , 4 , 5 ] . as_slice ( ) ) ;
265
251
assert_eq ! ( ref_ok. as_deref( ) , expected_result) ;
266
252
@@ -281,19 +267,21 @@ fn test_result_as_deref() {
281
267
// &Result<T: Deref, E: Deref>::Err(T).as_deref_err() ->
282
268
// Result<&T, &E::Deref::Target>::Err(&*E)
283
269
let ref_err = & Result :: Err :: < & u8 , & i32 > ( & 41 ) ;
284
- let expected_result = Result :: Err :: < & u8 , & i32 > ( & 41 ) ;
270
+ let expected_result = Result :: Err :: < & u8 , & & i32 > ( & & 41 ) ;
285
271
assert_eq ! ( ref_err. as_deref( ) , expected_result) ;
286
272
287
- let ref_err = & Result :: Err :: < & u32 , String > ( String :: from ( "an error" ) ) ;
288
- let expected_result = Result :: Err :: < & u32 , & str > ( "an error" ) ;
273
+ let s = String :: from ( "an error" ) ;
274
+ let ref_err = & Result :: Err :: < & u32 , String > ( s. clone ( ) ) ;
275
+ let expected_result = Result :: Err :: < & u32 , & String > ( & s) ;
289
276
assert_eq ! ( ref_err. as_deref( ) , expected_result) ;
290
277
291
- let ref_err = & Result :: Err :: < & u32 , Vec < i32 > > ( vec ! [ 5 , 4 , 3 , 2 , 1 ] ) ;
292
- let expected_result = Result :: Err :: < & u32 , & [ i32 ] > ( [ 5 , 4 , 3 , 2 , 1 ] . as_slice ( ) ) ;
278
+ let v = vec ! [ 5 , 4 , 3 , 2 , 1 ] ;
279
+ let ref_err = & Result :: Err :: < & u32 , Vec < i32 > > ( v. clone ( ) ) ;
280
+ let expected_result = Result :: Err :: < & u32 , & Vec < i32 > > ( & v) ;
293
281
assert_eq ! ( ref_err. as_deref( ) , expected_result) ;
294
282
295
283
// The following cases test calling `as_deref_*` with the wrong variant (i.e.
296
- // `as_deref_ok ()` with a `Result::Err()`, or `as_deref_err()` with a `Result::Ok()`.
284
+ // `as_deref ()` with a `Result::Err()`, or `as_deref_err()` with a `Result::Ok()`.
297
285
// While uncommon, these cases are supported to ensure that an `as_deref_*`
298
286
// call can still be made even when one of the Result types does not implement
299
287
// `Deref` (for example, std::io::Error).
@@ -312,56 +300,38 @@ fn test_result_as_deref() {
312
300
let expected_result = Result :: Ok :: < & [ i32 ; 5 ] , & u32 > ( & [ 1 , 2 , 3 , 4 , 5 ] ) ;
313
301
assert_eq ! ( ref_ok. as_deref_err( ) , expected_result) ;
314
302
315
- // &Result<T: Deref, E>::Err(E).as_deref_ok () ->
303
+ // &Result<T: Deref, E>::Err(E).as_deref () ->
316
304
// Result<&T::Deref::Target, &E>::Err(&E)
317
305
let ref_err = & Result :: Err :: < & u8 , i32 > ( 41 ) ;
318
306
let expected_result = Result :: Err :: < & u8 , & i32 > ( & 41 ) ;
319
- assert_eq ! ( ref_err. as_deref_ok ( ) , expected_result) ;
307
+ assert_eq ! ( ref_err. as_deref ( ) , expected_result) ;
320
308
321
309
let ref_err = & Result :: Err :: < & u32 , & str > ( "an error" ) ;
322
310
let expected_result = Result :: Err :: < & u32 , & & str > ( & "an error" ) ;
323
- assert_eq ! ( ref_err. as_deref_ok ( ) , expected_result) ;
311
+ assert_eq ! ( ref_err. as_deref ( ) , expected_result) ;
324
312
325
313
let ref_err = & Result :: Err :: < & u32 , [ i32 ; 5 ] > ( [ 5 , 4 , 3 , 2 , 1 ] ) ;
326
314
let expected_result = Result :: Err :: < & u32 , & [ i32 ; 5 ] > ( & [ 5 , 4 , 3 , 2 , 1 ] ) ;
327
- assert_eq ! ( ref_err. as_deref_ok ( ) , expected_result) ;
315
+ assert_eq ! ( ref_err. as_deref ( ) , expected_result) ;
328
316
}
329
317
330
318
#[ test]
331
319
fn test_result_as_deref_mut ( ) {
332
- // &mut Result<T: Deref, E>::Ok(T).as_deref_mut_ok () ->
320
+ // &mut Result<T: Deref, E>::Ok(T).as_deref_mut () ->
333
321
// Result<&mut T::Deref::Target, &mut E>::Ok(&mut *T)
334
322
let mut val = 42 ;
335
323
let mut expected_val = 42 ;
336
324
let mut_ok = & mut Result :: Ok :: < & mut i32 , u8 > ( & mut val) ;
337
325
let expected_result = Result :: Ok :: < & mut i32 , & mut u8 > ( & mut expected_val) ;
338
- assert_eq ! ( mut_ok. as_deref_mut_ok( ) , expected_result) ;
339
-
340
- let mut expected_string = String :: from ( "a result" ) ;
341
- let mut_ok = & mut Result :: Ok :: < String , u32 > ( expected_string. clone ( ) ) ;
342
- let expected_result = Result :: Ok :: < & mut str , & mut u32 > ( expected_string. deref_mut ( ) ) ;
343
- assert_eq ! ( mut_ok. as_deref_mut_ok( ) , expected_result) ;
344
-
345
- let mut expected_vec = vec ! [ 1 , 2 , 3 , 4 , 5 ] ;
346
- let mut_ok = & mut Result :: Ok :: < Vec < i32 > , u32 > ( expected_vec. clone ( ) ) ;
347
- let expected_result = Result :: Ok :: < & mut [ i32 ] , & mut u32 > ( expected_vec. as_mut_slice ( ) ) ;
348
- assert_eq ! ( mut_ok. as_deref_mut_ok( ) , expected_result) ;
349
-
350
- // &mut Result<T: Deref, E: Deref>::Ok(T).as_deref_mut() ->
351
- // Result<&mut T::Deref::Target, &mut E::Deref::Target>::Ok(&mut *T)
352
- let mut val = 42 ;
353
- let mut expected_val = 42 ;
354
- let mut_ok = & mut Result :: Ok :: < & mut i32 , & mut u8 > ( & mut val) ;
355
- let expected_result = Result :: Ok :: < & mut i32 , & mut u8 > ( & mut expected_val) ;
356
326
assert_eq ! ( mut_ok. as_deref_mut( ) , expected_result) ;
357
327
358
328
let mut expected_string = String :: from ( "a result" ) ;
359
- let mut_ok = & mut Result :: Ok :: < String , & mut u32 > ( expected_string. clone ( ) ) ;
329
+ let mut_ok = & mut Result :: Ok :: < String , u32 > ( expected_string. clone ( ) ) ;
360
330
let expected_result = Result :: Ok :: < & mut str , & mut u32 > ( expected_string. deref_mut ( ) ) ;
361
331
assert_eq ! ( mut_ok. as_deref_mut( ) , expected_result) ;
362
332
363
333
let mut expected_vec = vec ! [ 1 , 2 , 3 , 4 , 5 ] ;
364
- let mut_ok = & mut Result :: Ok :: < Vec < i32 > , & mut u32 > ( expected_vec. clone ( ) ) ;
334
+ let mut_ok = & mut Result :: Ok :: < Vec < i32 > , u32 > ( expected_vec. clone ( ) ) ;
365
335
let expected_result = Result :: Ok :: < & mut [ i32 ] , & mut u32 > ( expected_vec. as_mut_slice ( ) ) ;
366
336
assert_eq ! ( mut_ok. as_deref_mut( ) , expected_result) ;
367
337
@@ -386,23 +356,22 @@ fn test_result_as_deref_mut() {
386
356
// &mut Result<T: Deref, E: Deref>::Err(T).as_deref_mut_err() ->
387
357
// Result<&mut T, &mut E::Deref::Target>::Err(&mut *E)
388
358
let mut val = 41 ;
389
- let mut expected_val = 41 ;
390
- let mut_err = & mut Result :: Err :: < & mut u8 , & mut i32 > ( & mut val) ;
391
- let expected_result = Result :: Err :: < & mut u8 , & mut i32 > ( & mut expected_val) ;
359
+ let mut_err = & mut Result :: Err :: < & mut u8 , i32 > ( val) ;
360
+ let expected_result = Result :: Err :: < & mut u8 , & mut i32 > ( & mut val) ;
392
361
assert_eq ! ( mut_err. as_deref_mut( ) , expected_result) ;
393
362
394
363
let mut expected_string = String :: from ( "an error" ) ;
395
364
let mut_err = & mut Result :: Err :: < & mut u32 , String > ( expected_string. clone ( ) ) ;
396
- let expected_result = Result :: Err :: < & mut u32 , & mut str > ( expected_string. as_mut_str ( ) ) ;
365
+ let expected_result = Result :: Err :: < & mut u32 , & mut String > ( & mut expected_string) ;
397
366
assert_eq ! ( mut_err. as_deref_mut( ) , expected_result) ;
398
367
399
368
let mut expected_vec = vec ! [ 5 , 4 , 3 , 2 , 1 ] ;
400
369
let mut_err = & mut Result :: Err :: < & mut u32 , Vec < i32 > > ( expected_vec. clone ( ) ) ;
401
- let expected_result = Result :: Err :: < & mut u32 , & mut [ i32 ] > ( expected_vec. as_mut_slice ( ) ) ;
370
+ let expected_result = Result :: Err :: < & mut u32 , & mut Vec < i32 > > ( & mut expected_vec) ;
402
371
assert_eq ! ( mut_err. as_deref_mut( ) , expected_result) ;
403
372
404
373
// The following cases test calling `as_deref_mut_*` with the wrong variant (i.e.
405
- // `as_deref_mut_ok ()` with a `Result::Err()`, or `as_deref_mut_err()` with a `Result::Ok()`.
374
+ // `as_deref_mut ()` with a `Result::Err()`, or `as_deref_mut_err()` with a `Result::Ok()`.
406
375
// While uncommon, these cases are supported to ensure that an `as_deref_mut_*`
407
376
// call can still be made even when one of the Result types does not implement
408
377
// `Deref` (for example, std::io::Error).
@@ -426,22 +395,22 @@ fn test_result_as_deref_mut() {
426
395
let expected_result = Result :: Ok :: < & mut [ i32 ; 5 ] , & mut u32 > ( & mut expected_arr) ;
427
396
assert_eq ! ( mut_ok. as_deref_mut_err( ) , expected_result) ;
428
397
429
- // &mut Result<T: Deref, E>::Err(E).as_deref_mut_ok () ->
398
+ // &mut Result<T: Deref, E>::Err(E).as_deref_mut () ->
430
399
// Result<&mut T::Deref::Target, &mut E>::Err(&mut E)
431
400
let mut expected_val = 41 ;
432
401
let mut_err = & mut Result :: Err :: < & mut u8 , i32 > ( expected_val. clone ( ) ) ;
433
402
let expected_result = Result :: Err :: < & mut u8 , & mut i32 > ( & mut expected_val) ;
434
- assert_eq ! ( mut_err. as_deref_mut_ok ( ) , expected_result) ;
403
+ assert_eq ! ( mut_err. as_deref_mut ( ) , expected_result) ;
435
404
436
405
let string = String :: from ( "an error" ) ;
437
406
let expected_string = string. clone ( ) ;
438
407
let mut ref_str = expected_string. as_ref ( ) ;
439
408
let mut_err = & mut Result :: Err :: < & mut u32 , & str > ( string. as_str ( ) ) ;
440
409
let expected_result = Result :: Err :: < & mut u32 , & mut & str > ( & mut ref_str) ;
441
- assert_eq ! ( mut_err. as_deref_mut_ok ( ) , expected_result) ;
410
+ assert_eq ! ( mut_err. as_deref_mut ( ) , expected_result) ;
442
411
443
412
let mut expected_arr = [ 5 , 4 , 3 , 2 , 1 ] ;
444
413
let mut_err = & mut Result :: Err :: < & mut u32 , [ i32 ; 5 ] > ( expected_arr. clone ( ) ) ;
445
414
let expected_result = Result :: Err :: < & mut u32 , & mut [ i32 ; 5 ] > ( & mut expected_arr) ;
446
- assert_eq ! ( mut_err. as_deref_mut_ok ( ) , expected_result) ;
415
+ assert_eq ! ( mut_err. as_deref_mut ( ) , expected_result) ;
447
416
}
0 commit comments