Fix clippy lints in README.md and lib.rs

This commit is contained in:
Will Bush 2024-04-12 22:36:09 -05:00
parent 7388440a34
commit bdd9bb30ef
No known key found for this signature in database
GPG Key ID: 3823864B54B13BDA
2 changed files with 12 additions and 14 deletions

View File

@ -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<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;
pub fn some_tool() -> Result<Version> {
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<Version> {
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.

View File

@ -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<Version> {
//! 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<Version> {
//! 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<Version> {
//! 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.