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