mirror of https://github.com/zkat/miette.git
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:
parent
97766e8d90
commit
ea4296dace
13
README.md
13
README.md
|
|
@ -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.
|
||||||
|
|
|
||||||
14
src/lib.rs
14
src/lib.rs
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue