19
19
//! # #[allow(dead_code)]
20
20
//! enum Result<T, E> {
21
21
//! Ok(T),
22
- //! Err(E)
22
+ //! Err(E),
23
23
//! }
24
24
//! ```
25
25
//!
39
39
//! None => Err("invalid header length"),
40
40
//! Some(&1) => Ok(Version::Version1),
41
41
//! Some(&2) => Ok(Version::Version2),
42
- //! Some(_) => Err("invalid version")
42
+ //! Some(_) => Err("invalid version"),
43
43
//! }
44
44
//! }
45
45
//!
@@ -254,7 +254,7 @@ pub enum Result<T, E> {
254
254
255
255
/// Contains the error value
256
256
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
257
- Err ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] E )
257
+ Err ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] E ) ,
258
258
}
259
259
260
260
/////////////////////////////////////////////////////////////////////////////
@@ -270,6 +270,8 @@ impl<T, E> Result<T, E> {
270
270
///
271
271
/// # Examples
272
272
///
273
+ /// Basic usage:
274
+ ///
273
275
/// ```
274
276
/// let x: Result<i32, &str> = Ok(-3);
275
277
/// assert_eq!(x.is_ok(), true);
@@ -290,6 +292,8 @@ impl<T, E> Result<T, E> {
290
292
///
291
293
/// # Examples
292
294
///
295
+ /// Basic usage:
296
+ ///
293
297
/// ```
294
298
/// let x: Result<i32, &str> = Ok(-3);
295
299
/// assert_eq!(x.is_err(), false);
@@ -314,6 +318,8 @@ impl<T, E> Result<T, E> {
314
318
///
315
319
/// # Examples
316
320
///
321
+ /// Basic usage:
322
+ ///
317
323
/// ```
318
324
/// let x: Result<u32, &str> = Ok(2);
319
325
/// assert_eq!(x.ok(), Some(2));
@@ -337,6 +343,8 @@ impl<T, E> Result<T, E> {
337
343
///
338
344
/// # Examples
339
345
///
346
+ /// Basic usage:
347
+ ///
340
348
/// ```
341
349
/// let x: Result<u32, &str> = Ok(2);
342
350
/// assert_eq!(x.err(), None);
@@ -362,6 +370,10 @@ impl<T, E> Result<T, E> {
362
370
/// Produces a new `Result`, containing a reference
363
371
/// into the original, leaving the original in place.
364
372
///
373
+ /// # Examples
374
+ ///
375
+ /// Basic usage:
376
+ ///
365
377
/// ```
366
378
/// let x: Result<u32, &str> = Ok(2);
367
379
/// assert_eq!(x.as_ref(), Ok(&2));
@@ -380,6 +392,10 @@ impl<T, E> Result<T, E> {
380
392
381
393
/// Converts from `Result<T, E>` to `Result<&mut T, &mut E>`
382
394
///
395
+ /// # Examples
396
+ ///
397
+ /// Basic usage:
398
+ ///
383
399
/// ```
384
400
/// fn mutate(r: &mut Result<i32, i32>) {
385
401
/// match r.as_mut() {
@@ -445,6 +461,8 @@ impl<T, E> Result<T, E> {
445
461
///
446
462
/// # Examples
447
463
///
464
+ /// Basic usage:
465
+ ///
448
466
/// ```
449
467
/// fn stringify(x: u32) -> String { format!("error code: {}", x) }
450
468
///
@@ -471,6 +489,8 @@ impl<T, E> Result<T, E> {
471
489
///
472
490
/// # Examples
473
491
///
492
+ /// Basic usage:
493
+ ///
474
494
/// ```
475
495
/// let x: Result<u32, &str> = Ok(7);
476
496
/// assert_eq!(x.iter().next(), Some(&7));
@@ -488,6 +508,8 @@ impl<T, E> Result<T, E> {
488
508
///
489
509
/// # Examples
490
510
///
511
+ /// Basic usage:
512
+ ///
491
513
/// ```
492
514
/// let mut x: Result<u32, &str> = Ok(7);
493
515
/// match x.iter_mut().next() {
@@ -513,6 +535,8 @@ impl<T, E> Result<T, E> {
513
535
///
514
536
/// # Examples
515
537
///
538
+ /// Basic usage:
539
+ ///
516
540
/// ```
517
541
/// let x: Result<u32, &str> = Ok(2);
518
542
/// let y: Result<&str, &str> = Err("late error");
@@ -545,6 +569,8 @@ impl<T, E> Result<T, E> {
545
569
///
546
570
/// # Examples
547
571
///
572
+ /// Basic usage:
573
+ ///
548
574
/// ```
549
575
/// fn sq(x: u32) -> Result<u32, u32> { Ok(x * x) }
550
576
/// fn err(x: u32) -> Result<u32, u32> { Err(x) }
@@ -567,6 +593,8 @@ impl<T, E> Result<T, E> {
567
593
///
568
594
/// # Examples
569
595
///
596
+ /// Basic usage:
597
+ ///
570
598
/// ```
571
599
/// let x: Result<u32, &str> = Ok(2);
572
600
/// let y: Result<u32, &str> = Err("late error");
@@ -599,6 +627,8 @@ impl<T, E> Result<T, E> {
599
627
///
600
628
/// # Examples
601
629
///
630
+ /// Basic usage:
631
+ ///
602
632
/// ```
603
633
/// fn sq(x: u32) -> Result<u32, u32> { Ok(x * x) }
604
634
/// fn err(x: u32) -> Result<u32, u32> { Err(x) }
@@ -622,6 +652,8 @@ impl<T, E> Result<T, E> {
622
652
///
623
653
/// # Examples
624
654
///
655
+ /// Basic usage:
656
+ ///
625
657
/// ```
626
658
/// let optb = 2;
627
659
/// let x: Result<u32, &str> = Ok(9);
@@ -644,6 +676,8 @@ impl<T, E> Result<T, E> {
644
676
///
645
677
/// # Examples
646
678
///
679
+ /// Basic usage:
680
+ ///
647
681
/// ```
648
682
/// fn count(x: &str) -> usize { x.len() }
649
683
///
@@ -670,6 +704,8 @@ impl<T, E: fmt::Debug> Result<T, E> {
670
704
///
671
705
/// # Examples
672
706
///
707
+ /// Basic usage:
708
+ ///
673
709
/// ```
674
710
/// let x: Result<u32, &str> = Ok(2);
675
711
/// assert_eq!(x.unwrap(), 2);
@@ -696,6 +732,9 @@ impl<T, E: fmt::Debug> Result<T, E> {
696
732
/// passed message, and the content of the `Err`.
697
733
///
698
734
/// # Examples
735
+ ///
736
+ /// Basic usage:
737
+ ///
699
738
/// ```{.should_panic}
700
739
/// let x: Result<u32, &str> = Err("emergency failure");
701
740
/// x.expect("Testing expect"); // panics with `Testing expect: emergency failure`
@@ -759,6 +798,8 @@ impl<T, E> IntoIterator for Result<T, E> {
759
798
///
760
799
/// # Examples
761
800
///
801
+ /// Basic usage:
802
+ ///
762
803
/// ```
763
804
/// let x: Result<u32, &str> = Ok(5);
764
805
/// let v: Vec<u32> = x.into_iter().collect();
0 commit comments