@@ -556,13 +556,15 @@ macro_rules! unreachable {
556
556
} ) ;
557
557
}
558
558
559
- /// Indicates unfinished code by panicking with a message of "not yet implemented".
559
+ /// Indicates unimplemented code by panicking with a message of "not implemented".
560
560
///
561
561
/// This allows the your code to type-check, which is useful if you are prototyping or
562
562
/// implementing a trait that requires multiple methods which you don't plan of using all of.
563
563
///
564
- /// There is no difference between `unimplemented!` and `todo!` apart from the
565
- /// name.
564
+ /// The difference between `unimplemented!` and [`todo!`](macro.todo.html) is that while `todo!`
565
+ /// conveys an intent of implementing the functionality later and the message is "not yet
566
+ /// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
567
+ /// Also some IDEs will mark `todo!`s.
566
568
///
567
569
/// # Panics
568
570
///
@@ -573,7 +575,7 @@ macro_rules! unreachable {
573
575
///
574
576
/// # Examples
575
577
///
576
- /// Here's an example of some in-progress code. We have a trait `Foo`:
578
+ /// Say we have a trait `Foo`:
577
579
///
578
580
/// ```
579
581
/// trait Foo {
@@ -583,13 +585,13 @@ macro_rules! unreachable {
583
585
/// }
584
586
/// ```
585
587
///
586
- /// We want to implement `Foo` for 'MyStruct', but so far we only know how to
587
- /// implement the `bar()` function. `baz()` and `qux()` will still need to be defined
588
+ /// We want to implement `Foo` for 'MyStruct', but for some reason it only makes sense
589
+ /// to implement the `bar()` function. `baz()` and `qux()` will still need to be defined
588
590
/// in our implementation of `Foo`, but we can use `unimplemented!` in their definitions
589
591
/// to allow our code to compile.
590
592
///
591
- /// In the meantime, we want to have our program stop running once these
592
- /// unimplemented functions are reached.
593
+ /// We still want to have our program stop running if the unimplemented methods are
594
+ /// reached.
593
595
///
594
596
/// ```
595
597
/// # trait Foo {
@@ -605,19 +607,18 @@ macro_rules! unreachable {
605
607
/// }
606
608
///
607
609
/// fn baz(&self) {
608
- /// // We aren't sure how to even start writing baz yet,
609
- /// // so we have no logic here at all.
610
- /// // This will display "thread 'main' panicked at 'not yet implemented'".
610
+ /// // It makes no sense to `baz` a `MyStruct`, so we have no logic here
611
+ /// // at all.
612
+ /// // This will display "thread 'main' panicked at 'not implemented'".
611
613
/// unimplemented!();
612
614
/// }
613
615
///
614
616
/// fn qux(&self) -> Result<u64, ()> {
615
- /// let n = self.bar();
616
617
/// // We have some logic here,
617
- /// // so we can use unimplemented! to display what we have so far .
618
+ /// // We can add a message to unimplemented! to display our omission .
618
619
/// // This will display:
619
- /// // "thread 'main' panicked at 'not yet implemented: we need to divide by 2 '".
620
- /// unimplemented!("we need to divide by {}", n );
620
+ /// // "thread 'main' panicked at 'not implemented: MyStruct isn't quxable '".
621
+ /// unimplemented!("MyStruct isn't quxable" );
621
622
/// }
622
623
/// }
623
624
///
@@ -629,17 +630,21 @@ macro_rules! unreachable {
629
630
#[ macro_export]
630
631
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
631
632
macro_rules! unimplemented {
632
- ( ) => ( panic!( "not yet implemented" ) ) ;
633
- ( $( $arg: tt) +) => ( panic!( "not yet implemented: {}" , $crate:: format_args!( $( $arg) +) ) ) ;
633
+ ( ) => ( panic!( "not implemented" ) ) ;
634
+ ( $( $arg: tt) +) => ( panic!( "not implemented: {}" , $crate:: format_args!( $( $arg) +) ) ) ;
634
635
}
635
636
636
637
/// Indicates unfinished code.
637
638
///
638
639
/// This can be useful if you are prototyping and are just looking to have your
639
640
/// code typecheck.
640
641
///
641
- /// There is no difference between `unimplemented!` and `todo!` apart from the
642
- /// name.
642
+ /// The difference between [`unimplemented!`] and `todo!` is that while `todo!` conveys
643
+ /// an intent of implementing the functionality later and the message is "not yet
644
+ /// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
645
+ /// Also some IDEs will mark `todo!`s.
646
+ ///
647
+ /// [`unimplemented!`]: macro.unimplemented.html
643
648
///
644
649
/// # Panics
645
650
///
@@ -682,7 +687,7 @@ macro_rules! unimplemented {
682
687
/// let s = MyStruct;
683
688
/// s.bar();
684
689
///
685
- /// // we aren't even using baz() yet , so this is fine.
690
+ /// // we aren't even using baz(), so this is fine.
686
691
/// }
687
692
/// ```
688
693
#[ macro_export]
0 commit comments