mirror of https://github.com/zkat/miette.git
Add url field
This commit is contained in:
parent
53b21ead39
commit
a1f602c0fe
|
|
@ -22,6 +22,9 @@ pub struct MietteDiagnostic {
|
||||||
pub severity: Severity,
|
pub severity: Severity,
|
||||||
/// Additional help text related to this Diagnostic
|
/// Additional help text related to this Diagnostic
|
||||||
pub help: Option<String>,
|
pub help: Option<String>,
|
||||||
|
/// URL to visit for a more detailed explanation/help about this
|
||||||
|
/// [`Diagnostic`].
|
||||||
|
pub url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for MietteDiagnostic {
|
impl Display for MietteDiagnostic {
|
||||||
|
|
@ -50,6 +53,13 @@ impl Diagnostic for MietteDiagnostic {
|
||||||
.map(Box::new)
|
.map(Box::new)
|
||||||
.map(|c| c as Box<dyn Display>)
|
.map(|c| c as Box<dyn Display>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||||
|
self.url
|
||||||
|
.as_ref()
|
||||||
|
.map(Box::new)
|
||||||
|
.map(|c| c as Box<dyn Display>)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MietteDiagnostic {
|
impl MietteDiagnostic {
|
||||||
|
|
@ -70,6 +80,7 @@ impl MietteDiagnostic {
|
||||||
severity: Severity::Error,
|
severity: Severity::Error,
|
||||||
code: None,
|
code: None,
|
||||||
help: None,
|
help: None,
|
||||||
|
url: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,4 +131,25 @@ impl MietteDiagnostic {
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return new diagnostic with the given URL.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```
|
||||||
|
/// use miette::{Diagnostic, MietteDiagnostic};
|
||||||
|
///
|
||||||
|
/// let diag = MietteDiagnostic::new("PC is not working")
|
||||||
|
/// .with_url("https://letmegooglethat.com/?q=Why+my+pc+doesn%27t+work");
|
||||||
|
/// assert_eq!(diag.description, "PC is not working");
|
||||||
|
/// assert_eq!(
|
||||||
|
/// diag.url,
|
||||||
|
/// Some("https://letmegooglethat.com/?q=Why+my+pc+doesn%27t+work".to_string())
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
|
pub fn with_url(self, url: impl Into<String>) -> Self {
|
||||||
|
Self {
|
||||||
|
url: Some(url.into()),
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue