1 use std::fmt::Display; 2 use std::path::{self, Path, PathBuf}; 3 4 #[doc(hidden)] 5 pub trait AsDisplay<'a> { 6 // TODO: convert to generic associated type. 7 // https://github.com/dtolnay/thiserror/pull/253 8 type Target: Display; 9 as_display(&'a self) -> Self::Target10 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 as_display(&'a self) -> Self::Target19 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] as_display(&'a self) -> Self::Target28 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] as_display(&'a self) -> Self::Target37 fn as_display(&'a self) -> Self::Target { 38 self.display() 39 } 40 } 41