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
|
||||
/// format (`foo::bar::baz`) is recommended, but more classic codes like
|
||||
/// `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
|
||||
/// 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
|
||||
/// 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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -163,7 +163,9 @@ impl DiagnosticReporter for JokeReporter {
|
|||
"me, with {} {}: {}",
|
||||
sev,
|
||||
diagnostic,
|
||||
diagnostic.help().unwrap_or(&"have you tried not failing?")
|
||||
diagnostic
|
||||
.help()
|
||||
.unwrap_or_else(|| Box::new(&"have you tried not failing?"))
|
||||
)?;
|
||||
writeln!(
|
||||
f,
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ impl fmt::Debug for MyBad {
|
|||
}
|
||||
|
||||
impl Diagnostic for MyBad {
|
||||
fn code(&self) -> &(dyn std::fmt::Display) {
|
||||
&"oops::my::bad"
|
||||
fn code(&self) -> Box<dyn std::fmt::Display> {
|
||||
Box::new(&"oops::my::bad")
|
||||
}
|
||||
|
||||
fn help(&self) -> Option<&(dyn std::fmt::Display)> {
|
||||
Some(&"try doing it better next time?")
|
||||
fn help(&self) -> Option<Box<dyn std::fmt::Display>> {
|
||||
Some(Box::new(&"try doing it better next time?"))
|
||||
}
|
||||
|
||||
fn snippets(&self) -> Option<Box<dyn Iterator<Item = DiagnosticSnippet>>> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue