| 1 | use core::fmt::Display; | 
| 2 | use std::path::{self, Path, PathBuf}; | 
|---|
| 3 |  | 
|---|
| 4 | #[ doc(hidden)] | 
|---|
| 5 | pub 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 |  | 
|---|
| 13 | impl<'a, T> AsDisplay<'a> for &T | 
|---|
| 14 | where | 
|---|
| 15 | T: Display + 'a, | 
|---|
| 16 | { | 
|---|
| 17 | type Target = &'a T; | 
|---|
| 18 |  | 
|---|
| 19 | fn as_display(&'a self) -> Self::Target { | 
|---|
| 20 | *self | 
|---|
| 21 | } | 
|---|
| 22 | } | 
|---|
| 23 |  | 
|---|
| 24 | impl<'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 |  | 
|---|
| 33 | impl<'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)] | 
|---|
| 43 | pub trait Sealed {} | 
|---|
| 44 | impl<T: Display> Sealed for &T {} | 
|---|
| 45 | impl Sealed for Path {} | 
|---|
| 46 | impl Sealed for PathBuf {} | 
|---|
| 47 |  | 
|---|