File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -251,15 +251,18 @@ impl InodeTable {
251251 }
252252}
253253
254- /// Facilitates comparing Rc<PathBuf> and &Path
254+ /// Facilitates comparing Arc<PathBuf> and &Path.
255+ ///
256+ /// We can't implement arbitrary traits like Borrow<Path> on Arc<PathBuf>, but we can invent our
257+ /// own type like this that's identical to Path, and use that instead.
255258#[ derive( Debug ) ]
256- struct Pathish {
257- inner : Path ,
258- }
259+ #[ repr( transparent) ]
260+ struct Pathish ( Path ) ;
259261
260262impl Pathish {
261263 pub fn new ( p : & Path ) -> & Pathish {
262- unsafe { & * ( p as * const _ as * const Pathish ) }
264+ // safe because Path and Pathish are identical, guarenteed by #[repr(transparent)]
265+ unsafe { std:: mem:: transmute ( p) }
263266 }
264267}
265268
@@ -277,16 +280,15 @@ impl PartialOrd<Self> for Pathish {
277280
278281impl Ord for Pathish {
279282 fn cmp ( & self , other : & Self ) -> Ordering {
280- self . inner . cmp ( & other. inner )
283+ self . 0 . cmp ( & other. 0 )
281284 }
282285}
283286
284- impl Eq for Pathish {
285- }
287+ impl Eq for Pathish { }
286288
287289impl PartialEq for Pathish {
288290 fn eq ( & self , other : & Pathish ) -> bool {
289- self . inner . eq ( & other. inner )
291+ self . 0 . eq ( & other. 0 )
290292 }
291293}
292294
You can’t perform that action at this time.
0 commit comments