@@ -719,7 +719,8 @@ macro_rules! unreachable {
719
719
/// The difference between `unimplemented!` and [`todo!`] is that while `todo!`
720
720
/// conveys an intent of implementing the functionality later and the message is "not yet
721
721
/// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
722
- /// Also some IDEs will mark `todo!`s.
722
+ ///
723
+ /// Also, some IDEs will mark `todo!`s.
723
724
///
724
725
/// # Panics
725
726
///
@@ -805,50 +806,63 @@ macro_rules! unimplemented {
805
806
/// The difference between [`unimplemented!`] and `todo!` is that while `todo!` conveys
806
807
/// an intent of implementing the functionality later and the message is "not yet
807
808
/// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
808
- /// Also some IDEs will mark `todo!`s.
809
+ ///
810
+ /// Also, some IDEs will mark `todo!`s.
809
811
///
810
812
/// # Panics
811
813
///
812
- /// This will always [`panic!`].
814
+ /// This will always [`panic!`] because `todo!` is just a shorthand for `panic!` with a
815
+ /// fixed, specific message.
816
+ ///
817
+ /// Like `panic!`, this macro has a second form for displaying custom values.
813
818
///
814
819
/// # Examples
815
820
///
816
821
/// Here's an example of some in-progress code. We have a trait `Foo`:
817
822
///
818
823
/// ```
819
824
/// trait Foo {
820
- /// fn bar(&self);
825
+ /// fn bar(&self) -> u8 ;
821
826
/// fn baz(&self);
827
+ /// fn qux(&self) -> Result<u64, ()>;
822
828
/// }
823
829
/// ```
824
830
///
825
831
/// We want to implement `Foo` on one of our types, but we also want to work on
826
832
/// just `bar()` first. In order for our code to compile, we need to implement
827
- /// `baz()`, so we can use `todo!`:
833
+ /// `baz()` and `qux()` , so we can use `todo!`:
828
834
///
829
835
/// ```
830
836
/// # trait Foo {
831
- /// # fn bar(&self);
837
+ /// # fn bar(&self) -> u8 ;
832
838
/// # fn baz(&self);
839
+ /// # fn qux(&self) -> Result<u64, ()>;
833
840
/// # }
834
841
/// struct MyStruct;
835
842
///
836
843
/// impl Foo for MyStruct {
837
- /// fn bar(&self) {
838
- /// // implementation goes here
844
+ /// fn bar(&self) -> u8 {
845
+ /// 1 + 1
839
846
/// }
840
847
///
841
848
/// fn baz(&self) {
842
- /// // let 's not worry about implementing baz() for now
849
+ /// // Let 's not worry about implementing baz() for now
843
850
/// todo!();
844
851
/// }
852
+ ///
853
+ /// fn qux(&self) -> Result<u64, ()> {
854
+ /// // We can add a message to todo! to display our omission.
855
+ /// // This will display:
856
+ /// // "thread 'main' panicked at 'not yet implemented: MyStruct is not yet quxable'".
857
+ /// todo!("MyStruct is not yet quxable");
858
+ /// }
845
859
/// }
846
860
///
847
861
/// fn main() {
848
862
/// let s = MyStruct;
849
863
/// s.bar();
850
864
///
851
- /// // we aren't even using baz(), so this is fine.
865
+ /// // We aren't even using baz() or qux (), so this is fine.
852
866
/// }
853
867
/// ```
854
868
#[ macro_export]
0 commit comments