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