error_annotation/annotatable.rs
1use crate::ErrorAnnotation;
2use std::fmt::Display;
3
4/// An `Annotatable` error type is can convert an [ErrorAnnotation] with `Self` as the source type
5/// back into `Self`, provided the annotated `info` implements [std::fmt::Display].
6///
7/// A prime example is the [std::io::Error] impl, which can be used to convert any annotation on a
8/// [std::io::Error] back into a [std::io::Error], as the [`crate`]-level example demonstrates.
9///
10/// The conversion provided by implementations of `Annotatable` is typically conveniently
11/// accomplished via [AnnotateResult::annotate_err_into](crate::AnnotateResult::annotate_err_into).
12pub trait Annotatable: Sized {
13 fn merge_annotation<I>(ea: ErrorAnnotation<Self, I>) -> Self
14 where
15 I: Display;
16}
17
18impl Annotatable for std::io::Error {
19 fn merge_annotation<I>(ea: ErrorAnnotation<Self, I>) -> Self
20 where
21 I: Display,
22 {
23 Self::new(ea.source.kind(), ea.to_string())
24 }
25}