mirror of https://github.com/zkat/miette.git
feat(protocol): Simplify protocol return values further
BREAKING CHANGE: Switched to Box instead of & for help/code return values.
This commit is contained in:
parent
a04239cf35
commit
02dd1f84d4
|
|
@ -18,7 +18,7 @@ pub trait Diagnostic: std::error::Error {
|
||||||
/// the toplevel crate's documentation for easy searching. Rust path
|
/// the toplevel crate's documentation for easy searching. Rust path
|
||||||
/// format (`foo::bar::baz`) is recommended, but more classic codes like
|
/// format (`foo::bar::baz`) is recommended, but more classic codes like
|
||||||
/// `E0123` or Enums will work just fine.
|
/// `E0123` or Enums will work just fine.
|
||||||
fn code(&self) -> &(dyn Display);
|
fn code<'a>(&'a self) -> Box<dyn Display + 'a>;
|
||||||
|
|
||||||
/// Diagnostic severity. This may be used by [DiagnosticReporter]s to change the
|
/// Diagnostic severity. This may be used by [DiagnosticReporter]s to change the
|
||||||
/// display format of this diagnostic.
|
/// display format of this diagnostic.
|
||||||
|
|
@ -30,7 +30,7 @@ pub trait Diagnostic: std::error::Error {
|
||||||
|
|
||||||
/// Additional help text related to this Diagnostic. Do you have any
|
/// Additional help text related to this Diagnostic. Do you have any
|
||||||
/// advice for the poor soul who's just run into this issue?
|
/// advice for the poor soul who's just run into this issue?
|
||||||
fn help(&self) -> Option<&(dyn Display)> {
|
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,9 @@ impl DiagnosticReporter for JokeReporter {
|
||||||
"me, with {} {}: {}",
|
"me, with {} {}: {}",
|
||||||
sev,
|
sev,
|
||||||
diagnostic,
|
diagnostic,
|
||||||
diagnostic.help().unwrap_or(&"have you tried not failing?")
|
diagnostic
|
||||||
|
.help()
|
||||||
|
.unwrap_or_else(|| Box::new(&"have you tried not failing?"))
|
||||||
)?;
|
)?;
|
||||||
writeln!(
|
writeln!(
|
||||||
f,
|
f,
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,12 @@ impl fmt::Debug for MyBad {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic for MyBad {
|
impl Diagnostic for MyBad {
|
||||||
fn code(&self) -> &(dyn std::fmt::Display) {
|
fn code(&self) -> Box<dyn std::fmt::Display> {
|
||||||
&"oops::my::bad"
|
Box::new(&"oops::my::bad")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help(&self) -> Option<&(dyn std::fmt::Display)> {
|
fn help(&self) -> Option<Box<dyn std::fmt::Display>> {
|
||||||
Some(&"try doing it better next time?")
|
Some(Box::new(&"try doing it better next time?"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn snippets(&self) -> Option<Box<dyn Iterator<Item = DiagnosticSnippet>>> {
|
fn snippets(&self) -> Option<Box<dyn Iterator<Item = DiagnosticSnippet>>> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue