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
This commit is contained in:
Will Bush 2024-04-13 01:11:30 -05:00 committed by GitHub
parent 97766e8d90
commit ea4296dace
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 15 deletions

View File

@ -132,7 +132,6 @@ fn this_fails() -> Result<()> {
// You can use plain strings as a `Source`, or anything that implements // You can use plain strings as a `Source`, or anything that implements
// the one-method `Source` trait. // the one-method `Source` trait.
let src = "source\n text\n here".to_string(); let src = "source\n text\n here".to_string();
let len = src.len();
Err(MyBad { Err(MyBad {
src: NamedSource::new("bad_file.rs", src), src: NamedSource::new("bad_file.rs", src),
@ -247,7 +246,7 @@ use miette::{IntoDiagnostic, Result};
use semver::Version; use semver::Version;
pub fn some_tool() -> Result<Version> { pub fn some_tool() -> Result<Version> {
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; use semver::Version;
pub fn some_tool() -> Result<Version> { pub fn some_tool() -> Result<Version> {
Ok("1.2.x" "1.2.x"
.parse() .parse()
.into_diagnostic() .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: To construct your own simple adhoc error use the [miette!] macro:
```rust ```rust
// my_app/lib/my_internal_file.rs // my_app/lib/my_internal_file.rs
use miette::{miette, IntoDiagnostic, Result, WrapErr}; use miette::{miette, Result};
use semver::Version; use semver::Version;
pub fn some_tool() -> Result<Version> { pub fn some_tool() -> Result<Version> {
let version = "1.2.x"; let version = "1.2.x";
Ok(version version
.parse() .parse()
.map_err(|_| miette!("Invalid version {}", version))?) .map_err(|_| miette!("Invalid version {}", version))
} }
``` ```
There are also similar [bail!] and [ensure!] macros. There are also similar [bail!] and [ensure!] macros.

View File

@ -131,7 +131,6 @@
//! // You can use plain strings as a `Source`, or anything that implements //! // You can use plain strings as a `Source`, or anything that implements
//! // the one-method `Source` trait. //! // the one-method `Source` trait.
//! let src = "source\n text\n here".to_string(); //! let src = "source\n text\n here".to_string();
//! let len = src.len();
//! //!
//! Err(MyBad { //! Err(MyBad {
//! src: NamedSource::new("bad_file.rs", src), //! src: NamedSource::new("bad_file.rs", src),
@ -246,7 +245,7 @@
//! use semver::Version; //! use semver::Version;
//! //!
//! pub fn some_tool() -> Result<Version> { //! pub fn some_tool() -> Result<Version> {
//! Ok("1.2.x".parse().into_diagnostic()?) //! "1.2.x".parse().into_diagnostic()
//! } //! }
//! ``` //! ```
//! //!
@ -261,24 +260,24 @@
//! use semver::Version; //! use semver::Version;
//! //!
//! pub fn some_tool() -> Result<Version> { //! pub fn some_tool() -> Result<Version> {
//! Ok("1.2.x" //! "1.2.x"
//! .parse() //! .parse()
//! .into_diagnostic() //! .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: //! To construct your own simple adhoc error use the [miette!] macro:
//! ```rust //! ```rust
//! // my_app/lib/my_internal_file.rs //! // my_app/lib/my_internal_file.rs
//! use miette::{miette, IntoDiagnostic, Result, WrapErr}; //! use miette::{miette, Result};
//! use semver::Version; //! use semver::Version;
//! //!
//! pub fn some_tool() -> Result<Version> { //! pub fn some_tool() -> Result<Version> {
//! let version = "1.2.x"; //! let version = "1.2.x";
//! Ok(version //! version
//! .parse() //! .parse()
//! .map_err(|_| miette!("Invalid version {}", version))?) //! .map_err(|_| miette!("Invalid version {}", version))
//! } //! }
//! ``` //! ```
//! There are also similar [bail!] and [ensure!] macros. //! 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 //! See the docs for [`MietteHandlerOpts`] for more details on what you can