mirror of https://github.com/zkat/miette.git
add example to README and docs fixing #96
This commit is contained in:
parent
a8b4ae012a
commit
f9be9bc9f0
17
README.md
17
README.md
|
|
@ -305,6 +305,23 @@ enabled:
|
||||||
miette = { version = "X.Y.Z", features = ["fancy"] }
|
miette = { version = "X.Y.Z", features = ["fancy"] }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Another way to display a diagnostic is by printing them using the debug formatter.
|
||||||
|
This is, in fact, what returning diagnostics from main ends up doing.
|
||||||
|
To do it yourself, you can write the following:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use miette::{IntoDiagnostic, Result};
|
||||||
|
use semver::Version;
|
||||||
|
|
||||||
|
fn just_a_random_function() {
|
||||||
|
let version_result: Result<Version> = "1.2.x".parse().into_diagnostic();
|
||||||
|
match version_result {
|
||||||
|
Err(e) => println!("{:?}", e),
|
||||||
|
Ok(version) => println!("{}", version),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### ... diagnostic code URLs
|
#### ... diagnostic code URLs
|
||||||
|
|
||||||
`miette` supports providing a URL for individual diagnostics. This URL will
|
`miette` supports providing a URL for individual diagnostics. This URL will
|
||||||
|
|
|
||||||
17
src/lib.rs
17
src/lib.rs
|
|
@ -304,6 +304,23 @@
|
||||||
//! miette = { version = "X.Y.Z", features = ["fancy"] }
|
//! miette = { version = "X.Y.Z", features = ["fancy"] }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
//! Another way to display a diagnostic is by printing them using the debug formatter.
|
||||||
|
//! This is, in fact, what returning diagnostics from main ends up doing.
|
||||||
|
//! To do it yourself, you can write the following:
|
||||||
|
//!
|
||||||
|
//! ```rust
|
||||||
|
//! use miette::{IntoDiagnostic, Result};
|
||||||
|
//! use semver::Version;
|
||||||
|
//!
|
||||||
|
//! fn just_a_random_function() {
|
||||||
|
//! let version_result: Result<Version> = "1.2.x".parse().into_diagnostic();
|
||||||
|
//! match version_result {
|
||||||
|
//! Err(e) => println!("{:?}", e),
|
||||||
|
//! Ok(version) => println!("{}", version),
|
||||||
|
//! }
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
//! ### ... diagnostic code URLs
|
//! ### ... diagnostic code URLs
|
||||||
//!
|
//!
|
||||||
//! `miette` supports providing a URL for individual diagnostics. This URL will
|
//! `miette` supports providing a URL for individual diagnostics. This URL will
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue