@@ -811,6 +811,8 @@ impl dyn Error + Send + Sync {
811
811
/// An error reporter that exposes the entire error chain for printing.
812
812
/// It also exposes options for formatting the error chain, either entirely on a single line,
813
813
/// or in multi-line format with each cause in the error chain on a new line.
814
+ /// `Report` only requires that the wrapped error implements `Error`. It doesn't require that the
815
+ /// wrapped error be `Send`, `Sync`, or `'static`.
814
816
///
815
817
/// # Examples
816
818
///
@@ -822,68 +824,31 @@ impl dyn Error + Send + Sync {
822
824
/// use std::fmt;
823
825
///
824
826
/// #[derive(Debug)]
825
- /// struct SuperError {
826
- /// side: SuperErrorSideKick,
827
- /// }
828
- ///
829
- /// impl fmt::Display for SuperError {
830
- /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
831
- /// write!(f, "SuperError is here!")
832
- /// }
833
- /// }
834
- ///
835
- /// impl Error for SuperError {
836
- /// fn source(&self) -> Option<&(dyn Error + 'static)> {
837
- /// Some(&self.side)
838
- /// }
827
+ /// struct SuperError<'a> {
828
+ /// side: &'a str,
839
829
/// }
840
830
///
841
- /// #[derive(Debug)]
842
- /// struct SuperErrorSideKick;
843
- ///
844
- /// impl fmt::Display for SuperErrorSideKick {
831
+ /// impl<'a> fmt::Display for SuperError<'a> {
845
832
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
846
- /// write!(f, "SuperErrorSideKick is here!" )
833
+ /// write!(f, "SuperError is here: {}", self.side )
847
834
/// }
848
835
/// }
849
836
///
850
- /// impl Error for SuperErrorSideKick {}
837
+ /// impl<'a> Error for SuperError<'a> {}
851
838
///
852
839
/// // Note that the error doesn't need to be `Send` or `Sync`.
853
840
/// impl !Send for SuperError {}
854
841
/// impl !Sync for SuperError {}
855
842
///
856
843
/// fn main() {
857
- /// let error = SuperError { side: SuperErrorSideKick };
844
+ /// let msg = String::from("Huzzah!");
845
+ /// let error = SuperError { side: &msg };
858
846
/// let report = Report::new(&error).pretty(true);
859
847
///
860
848
/// println!("{}", report);
861
849
/// }
862
850
/// ```
863
- ///
864
- /// `Report` only requires that the wrapped error implements `Error`. It doesn't require that the
865
- /// wrapped error be `Send`, `Sync`, or `'static`.
866
- ///
867
- /// ```rust
868
- /// # #![feature(error_reporter)]
869
- /// # use std::fmt;
870
- /// # use std::error::{Error, Report};
871
- /// #[derive(Debug)]
872
- /// struct SuperError<'a> {
873
- /// side: &'a str,
874
- /// }
875
- /// impl<'a> fmt::Display for SuperError<'a> {
876
- /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
877
- /// write!(f, "SuperError is here: {}", self.side)
878
- /// }
879
- /// }
880
- /// impl<'a> Error for SuperError<'a> {}
881
- /// fn main() {
882
- /// let msg = String::from("Huzzah!");
883
- /// let report = Report::new(SuperError { side: &msg });
884
- /// println!("{}", report);
885
- /// }
886
- /// ```
851
+
887
852
#[ unstable( feature = "error_reporter" , issue = "90172" ) ]
888
853
pub struct Report < E > {
889
854
/// The error being reported.
0 commit comments