normpath/
cmp.rs

1//! Implementations of comparison traits copied and modified from The Rust
2//! Programming Language.
3//!
4//! Sources:
5//! - <https://github.com/rust-lang/rust/blob/b1277d04db0dc8009037e872a1be7cdc2bd74a43/library/std/src/path.rs#L2635-L2726>
6//!
7//! Copyrights:
8//! - Copyrights in the Rust project are retained by their contributors. No
9//!   copyright assignment is required to contribute to the Rust project.
10//!
11//!   Some files include explicit copyright notices and/or license notices.
12//!   For full authorship information, see the version control history or
13//!   <https://thanks.rust-lang.org>
14//!
15//!   <https://github.com/rust-lang/rust/blob/b1277d04db0dc8009037e872a1be7cdc2bd74a43/COPYRIGHT>
16//! - Modifications copyright (c) 2020 dylni (<https://github.com/dylni>)<br>
17//!   <https://github.com/dylni/normpath/blob/master/COPYRIGHT>
18
19use std::borrow::Cow;
20use std::cmp::Ordering;
21use std::path::Path;
22use std::path::PathBuf;
23
24use super::BasePath;
25use super::BasePathBuf;
26
27macro_rules! r#impl {
28    ( $left:ty , $right:ty ) => {
29        impl PartialEq<$right> for $left {
30            #[inline]
31            fn eq(&self, other: &$right) -> bool {
32                <BasePath as PartialEq<Path>>::eq(self, other.as_ref())
33            }
34        }
35
36        impl PartialEq<$left> for $right {
37            #[inline]
38            fn eq(&self, other: &$left) -> bool {
39                other == self
40            }
41        }
42
43        impl PartialOrd<$right> for $left {
44            #[inline]
45            fn partial_cmp(&self, other: &$right) -> Option<Ordering> {
46                <BasePath as PartialOrd<Path>>::partial_cmp(
47                    self,
48                    other.as_ref(),
49                )
50            }
51        }
52
53        impl PartialOrd<$left> for $right {
54            #[inline]
55            fn partial_cmp(&self, other: &$left) -> Option<Ordering> {
56                other.partial_cmp(self)
57            }
58        }
59    };
60}
61
62r#impl!(BasePathBuf, BasePath);
63r#impl!(BasePathBuf, &BasePath);
64r#impl!(Cow<'_, BasePath>, BasePath);
65r#impl!(Cow<'_, BasePath>, &BasePath);
66r#impl!(Cow<'_, BasePath>, BasePathBuf);
67
68r#impl!(BasePathBuf, Path);
69r#impl!(BasePathBuf, &Path);
70r#impl!(BasePathBuf, Cow<'_, Path>);
71r#impl!(BasePathBuf, PathBuf);
72r#impl!(BasePath, &Path);
73r#impl!(BasePath, Cow<'_, Path>);
74r#impl!(BasePath, PathBuf);
75r#impl!(&BasePath, Path);
76r#impl!(&BasePath, Cow<'_, Path>);
77r#impl!(&BasePath, PathBuf);