thiserror/
display.rs

1use core::fmt::Display;
2use std::path::{self, Path, PathBuf};
3
4#[doc(hidden)]
5pub trait AsDisplay<'a>: Sealed {
6    // TODO: convert to generic associated type.
7    // https://github.com/dtolnay/thiserror/pull/253
8    type Target: Display;
9
10    fn as_display(&'a self) -> Self::Target;
11}
12
13impl<'a, T> AsDisplay<'a> for &T
14where
15    T: Display + 'a,
16{
17    type Target = &'a T;
18
19    fn as_display(&'a self) -> Self::Target {
20        *self
21    }
22}
23
24impl<'a> AsDisplay<'a> for Path {
25    type Target = path::Display<'a>;
26
27    #[inline]
28    fn as_display(&'a self) -> Self::Target {
29        self.display()
30    }
31}
32
33impl<'a> AsDisplay<'a> for PathBuf {
34    type Target = path::Display<'a>;
35
36    #[inline]
37    fn as_display(&'a self) -> Self::Target {
38        self.display()
39    }
40}
41
42#[doc(hidden)]
43pub trait Sealed {}
44impl<T: Display> Sealed for &T {}
45impl Sealed for Path {}
46impl Sealed for PathBuf {}