Skip to content

Commit

Permalink
fix(clippy): Fix clippy lints in docs (#365)
Browse files Browse the repository at this point in the history
* Fix commented out code in lib.rs docs not found in README.md

* Fix clippy lints in README.md and lib.rs
  • Loading branch information
willbush committed Apr 13, 2024
1 parent 97766e8 commit ea4296d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
13 changes: 6 additions & 7 deletions README.md
Expand Up @@ -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),
Expand Down Expand Up @@ -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()
}
```

Expand All @@ -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.
Expand Down
14 changes: 6 additions & 8 deletions src/lib.rs
Expand Up @@ -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),
Expand Down Expand Up @@ -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()
//! }
//! ```
//!
Expand All @@ -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.
Expand Down Expand Up @@ -637,7 +636,6 @@
//! )
//! }))
//!
//! # .unwrap()
//! ```
//!
//! See the docs for [`MietteHandlerOpts`] for more details on what you can
Expand Down

0 comments on commit ea4296d

Please sign in to comment.