From ea4296dacec3b0e4762281d9d115c1bd69ecfac3 Mon Sep 17 00:00:00 2001 From: Will Bush Date: Sat, 13 Apr 2024 01:11:30 -0500 Subject: [PATCH] fix(clippy): Fix clippy lints in docs (#365) * Fix commented out code in lib.rs docs not found in README.md * Fix clippy lints in README.md and lib.rs --- README.md | 13 ++++++------- src/lib.rs | 14 ++++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c019259..88f8b99 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,6 @@ fn this_fails() -> Result<()> { // You can use plain strings as a `Source`, or anything that implements // the one-method `Source` trait. let src = "source\n text\n here".to_string(); - let len = src.len(); Err(MyBad { src: NamedSource::new("bad_file.rs", src), @@ -247,7 +246,7 @@ use miette::{IntoDiagnostic, Result}; use semver::Version; pub fn some_tool() -> Result { - Ok("1.2.x".parse().into_diagnostic()?) + "1.2.x".parse().into_diagnostic() } ``` @@ -262,24 +261,24 @@ use miette::{IntoDiagnostic, Result, WrapErr}; use semver::Version; pub fn some_tool() -> Result { - Ok("1.2.x" + "1.2.x" .parse() .into_diagnostic() - .wrap_err("Parsing this tool's semver version failed.")?) + .wrap_err("Parsing this tool's semver version failed.") } ``` To construct your own simple adhoc error use the [miette!] macro: ```rust // my_app/lib/my_internal_file.rs -use miette::{miette, IntoDiagnostic, Result, WrapErr}; +use miette::{miette, Result}; use semver::Version; pub fn some_tool() -> Result { let version = "1.2.x"; - Ok(version + version .parse() - .map_err(|_| miette!("Invalid version {}", version))?) + .map_err(|_| miette!("Invalid version {}", version)) } ``` There are also similar [bail!] and [ensure!] macros. diff --git a/src/lib.rs b/src/lib.rs index 5301e9e..2533fe9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,7 +131,6 @@ //! // You can use plain strings as a `Source`, or anything that implements //! // the one-method `Source` trait. //! let src = "source\n text\n here".to_string(); -//! let len = src.len(); //! //! Err(MyBad { //! src: NamedSource::new("bad_file.rs", src), @@ -246,7 +245,7 @@ //! use semver::Version; //! //! pub fn some_tool() -> Result { -//! Ok("1.2.x".parse().into_diagnostic()?) +//! "1.2.x".parse().into_diagnostic() //! } //! ``` //! @@ -261,24 +260,24 @@ //! use semver::Version; //! //! pub fn some_tool() -> Result { -//! Ok("1.2.x" +//! "1.2.x" //! .parse() //! .into_diagnostic() -//! .wrap_err("Parsing this tool's semver version failed.")?) +//! .wrap_err("Parsing this tool's semver version failed.") //! } //! ``` //! //! To construct your own simple adhoc error use the [miette!] macro: //! ```rust //! // my_app/lib/my_internal_file.rs -//! use miette::{miette, IntoDiagnostic, Result, WrapErr}; +//! use miette::{miette, Result}; //! use semver::Version; //! //! pub fn some_tool() -> Result { //! let version = "1.2.x"; -//! Ok(version +//! version //! .parse() -//! .map_err(|_| miette!("Invalid version {}", version))?) +//! .map_err(|_| miette!("Invalid version {}", version)) //! } //! ``` //! There are also similar [bail!] and [ensure!] macros. @@ -637,7 +636,6 @@ //! ) //! })) //! -//! # .unwrap() //! ``` //! //! See the docs for [`MietteHandlerOpts`] for more details on what you can