From 251d6d59292397458328ef57fb7957faedafd019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20D=C3=B6nszelmann?= Date: Wed, 15 Nov 2023 19:35:46 +0100 Subject: [PATCH] fix(docs): add example to README and docs fixing #96 (#319) --- README.md | 17 +++++++++++++++++ src/lib.rs | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index a29b428..5f79c52 100644 --- a/README.md +++ b/README.md @@ -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 = "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 diff --git a/src/lib.rs b/src/lib.rs index 08de732..d80efa7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 = "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