11#![ doc( html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png" ,
22 html_favicon_url = "https://www.rust-lang.org/favicon.ico" ,
3- html_root_url = "https://wisagan.github.io /simple-error/simple_error/ " ) ]
3+ html_root_url = "https://docs.rs /simple-error" ) ]
44#![ deny( missing_docs) ]
55//! A simple error type backed by a string.
66//!
7- //! This crate provides a `SimpleError` type, which implements `std::error::Error`. The underlying
8- //! is a `String` as the error message.
7+ //! This crate provides a `SimpleError` type, which implements `std::error::Error`.
8+ //! The underlying type is a `String` used as the error message.
99//!
1010//! It should be used when all you care about is an error string.
1111//!
@@ -29,7 +29,7 @@ impl SimpleError {
2929 /// # Examples
3030 ///
3131 /// ```
32- /// use self:: simple_error::SimpleError;
32+ /// use simple_error::SimpleError;
3333 ///
3434 /// // errors can be created from `str`
3535 /// let err = SimpleError::new("an error from str");
@@ -50,7 +50,7 @@ impl SimpleError {
5050 /// # Examples
5151 ///
5252 /// ```
53- /// use self:: simple_error::SimpleError;
53+ /// use simple_error::SimpleError;
5454 /// use std::io;
5555 ///
5656 /// // errors can be created from `io::Error`
@@ -72,7 +72,7 @@ impl SimpleError {
7272 /// # Examples
7373 ///
7474 /// ```
75- /// use self:: simple_error::SimpleError;
75+ /// use simple_error::SimpleError;
7676 ///
7777 /// let err = SimpleError::with("cannot turn on tv", SimpleError::new("remote not found"));
7878 /// assert_eq!("cannot turn on tv, remote not found", format!("{}", err));
@@ -87,7 +87,7 @@ impl SimpleError {
8787 /// # Examples
8888 ///
8989 /// ```
90- /// use self:: simple_error::SimpleError;
90+ /// use simple_error::SimpleError;
9191 ///
9292 /// let s = SimpleError::new("critical error");
9393 /// assert_eq!("critical error", s.as_str());
@@ -123,16 +123,16 @@ pub type SimpleResult<T> = Result<T, SimpleError>;
123123
124124/// Helper macro for unwrapping `Result` values while returning early with a
125125/// newly constructed `SimpleError` if the value of the expression is `Err`.
126- /// Can only be used in functions that return `Result<_, SimpleError>`.
126+ /// Can be used in functions that return `Result<_, E>` where `E: From<SimpleError>`
127+ /// (e.g. `SimpleError` or `Box<dyn Error>`).
127128///
128129///
129130/// # Examples
130131///
131- /// ```
132- /// # #[macro_use] extern crate simple_error;
133- /// # fn main() {
134- /// use self::simple_error::SimpleError;
135- /// use std::error::Error;
132+ /// ```
133+ /// # fn main() {
134+ /// use simple_error::{SimpleError, try_with};
135+ /// use std::error::Error;
136136///
137137/// fn try_block(result: Result<(), SimpleError>, s: &str) -> Result<(), SimpleError> {
138138/// Ok(try_with!(result, s))
@@ -186,16 +186,16 @@ macro_rules! try_with {
186186
187187/// Helper macro for unwrapping `Option` values while returning early with a
188188/// newly constructed `SimpleError` if the value of the expression is `None`.
189- /// Can only be used in functions that return `Result<_, SimpleError>`.
189+ /// Can be used in functions that return `Result<_, E>` where `E: From<SimpleError>`
190+ /// (e.g. `SimpleError` or `Box<dyn Error>`).
190191///
191192///
192193/// # Examples
193194///
194- /// ```
195- /// # #[macro_use] extern crate simple_error;
196- /// # fn main() {
197- /// use self::simple_error::SimpleError;
198- /// use std::error::Error;
195+ /// ```
196+ /// # fn main() {
197+ /// use simple_error::{SimpleError, require_with};
198+ /// use std::error::Error;
199199///
200200/// fn require_block(maybe: Option<()>, s: &str) -> Result<(), SimpleError> {
201201/// Ok(require_with!(maybe, s))
@@ -249,15 +249,15 @@ macro_rules! require_with {
249249
250250/// Helper macro for ensuring a boolean condition while returning early with a
251251/// newly constructed `SimpleError` if the condition is `false`.
252- /// Can only be used in functions that return `Result<_, SimpleError>`.
252+ /// Can be used in functions that return `Result<_, E>` where `E: From<SimpleError>`
253+ /// (e.g. `SimpleError` or `Box<dyn Error>`).
253254///
254255/// # Examples
255256///
256- /// ```
257- /// # #[macro_use] extern crate simple_error;
258- /// # fn main() {
259- /// use self::simple_error::SimpleError;
260- /// use std::error::Error;
257+ /// ```
258+ /// # fn main() {
259+ /// use simple_error::{SimpleError, ensure_with};
260+ /// use std::error::Error;
261261///
262262/// fn ensure_block(cond: bool, s: &str) -> Result<(), SimpleError> {
263263/// ensure_with!(cond, s);
@@ -310,11 +310,10 @@ macro_rules! ensure_with {
310310///
311311/// # Examples
312312///
313- /// ```
314- /// # #[macro_use] extern crate simple_error;
315- /// # fn main() {
316- /// use self::simple_error::SimpleError;
317- /// use std::error::Error;
313+ /// ```
314+ /// # fn main() {
315+ /// use simple_error::{SimpleError, bail};
316+ /// use std::error::Error;
318317/// // Use with a `Into<SimpleError>`
319318///
320319/// struct ErrorSeed;
@@ -364,10 +363,9 @@ macro_rules! bail {
364363///
365364/// # Example
366365///
367- /// ```
368- /// # #[macro_use] extern crate simple_error;
369- /// # fn main() {
370- /// use self::simple_error::SimpleResult;
366+ /// ```
367+ /// # fn main() {
368+ /// use simple_error::{SimpleResult, simple_error};
371369///
372370/// fn add_reason(r: Result<(), ()>) -> SimpleResult<()> {
373371/// // Use with a string slice
@@ -399,10 +397,9 @@ macro_rules! simple_error {
399397///
400398/// # Example
401399///
402- /// ```
403- /// # #[macro_use] extern crate simple_error;
404- /// # fn main() {
405- /// use self::simple_error::SimpleResult;
400+ /// ```
401+ /// # fn main() {
402+ /// use simple_error::{SimpleResult, map_err_with};
406403///
407404/// fn map_err_with_reason(r: Result<(), std::io::Error>) -> SimpleResult<()> {
408405/// // Use with a string slice
0 commit comments