fix(docs): add example to README and docs fixing #96 (#319)

This commit is contained in:
Jonathan Dönszelmann 2023-11-15 19:35:46 +01:00 committed by GitHub
parent fd77257cee
commit 251d6d5929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -305,6 +305,23 @@ enabled:
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
`miette` supports providing a URL for individual diagnostics. This URL will

View File

@ -304,6 +304,23 @@
//! 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
//!
//! `miette` supports providing a URL for individual diagnostics. This URL will