@@ -2,52 +2,45 @@ use std::fmt::{self, Display};
22use std:: path:: { Path , PathBuf } ;
33
44#[ doc( hidden) ]
5- pub trait AsDisplay {
6- type Target : Display + ? Sized ;
5+ pub trait AsDisplay < ' a > {
6+ type Target : Display ;
77
8- fn as_display ( & self ) -> & Self :: Target ;
8+ fn as_display ( & ' a self ) -> Self :: Target ;
99}
1010
11- impl < T : Display > AsDisplay for & T {
12- type Target = T ;
11+ impl < ' a , T > AsDisplay < ' a > for & T
12+ where
13+ T : Display + ' a ,
14+ {
15+ type Target = & ' a T ;
1316
14- fn as_display ( & self ) -> & Self :: Target {
15- self
17+ fn as_display ( & ' a self ) -> Self :: Target {
18+ * self
1619 }
1720}
1821
19- impl AsDisplay for Path {
20- type Target = PathDisplay ;
22+ impl < ' a > AsDisplay < ' a > for Path {
23+ type Target = PathDisplay < ' a > ;
2124
2225 #[ inline]
23- fn as_display ( & self ) -> & Self :: Target {
24- PathDisplay :: new ( self )
26+ fn as_display ( & ' a self ) -> Self :: Target {
27+ PathDisplay ( self )
2528 }
2629}
2730
28- impl AsDisplay for PathBuf {
29- type Target = PathDisplay ;
31+ impl < ' a > AsDisplay < ' a > for PathBuf {
32+ type Target = PathDisplay < ' a > ;
3033
3134 #[ inline]
32- fn as_display ( & self ) -> & Self :: Target {
33- PathDisplay :: new ( self . as_path ( ) )
35+ fn as_display ( & ' a self ) -> Self :: Target {
36+ PathDisplay ( self . as_path ( ) )
3437 }
3538}
3639
3740#[ doc( hidden) ]
38- #[ repr( transparent) ]
39- pub struct PathDisplay ( Path ) ;
41+ pub struct PathDisplay < ' a > ( & ' a Path ) ;
4042
41- impl PathDisplay {
42- #[ inline]
43- fn new ( path : & Path ) -> & Self {
44- // SAFETY: PathDisplay is repr(transparent) so casting pointers between
45- // it and its payload is safe.
46- unsafe { & * ( path as * const Path as * const Self ) }
47- }
48- }
49-
50- impl Display for PathDisplay {
43+ impl < ' a > Display for PathDisplay < ' a > {
5144 #[ inline]
5245 fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
5346 self . 0 . display ( ) . fmt ( formatter)
0 commit comments