diff options
| author | Yotam Ofek <yotam.ofek@gmail.com> | 2025-03-01 21:50:43 +0000 |
|---|---|---|
| committer | Yotam Ofek <yotam.ofek@gmail.com> | 2025-03-06 16:07:14 +0000 |
| commit | 329b8a312dc5fbe8a310a30b8ce452c7609e202c (patch) | |
| tree | 61702d5f7012fef32e2202a0550d5c94228aec4e | |
| parent | ccfbfe22922946249088bc9d574f7dc22c8f6c90 (diff) | |
| download | rust-329b8a312dc5fbe8a310a30b8ce452c7609e202c.tar.gz rust-329b8a312dc5fbe8a310a30b8ce452c7609e202c.zip | |
Implement `Ord` by-hand instead of `PartialOrd` for `Link`
| -rw-r--r-- | src/librustdoc/html/render/sidebar.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 64dbaf9083e..3130815af0b 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -79,7 +79,7 @@ impl<'a> LinkBlock<'a> { } /// A link to an item. Content should not be escaped. -#[derive(Ord, PartialEq, Eq, Hash, Clone)] +#[derive(PartialEq, Eq, Hash, Clone)] pub(crate) struct Link<'a> { /// The content for the anchor tag and title attr name: Cow<'a, str>, @@ -91,13 +91,13 @@ pub(crate) struct Link<'a> { children: Vec<Link<'a>>, } -impl PartialOrd for Link<'_> { - fn partial_cmp(&self, other: &Link<'_>) -> Option<Ordering> { +impl Ord for Link<'_> { + fn cmp(&self, other: &Self) -> Ordering { match compare_names(&self.name, &other.name) { - Ordering::Equal => (), - result => return Some(result), + Ordering::Equal => {} + result => return result, } - (&self.name_html, &self.href, &self.children).partial_cmp(&( + (&self.name_html, &self.href, &self.children).cmp(&( &other.name_html, &other.href, &other.children, @@ -105,6 +105,12 @@ impl PartialOrd for Link<'_> { } } +impl PartialOrd for Link<'_> { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + Some(self.cmp(other)) + } +} + impl<'a> Link<'a> { pub fn new(href: impl Into<Cow<'a, str>>, name: impl Into<Cow<'a, str>>) -> Self { Self { href: href.into(), name: name.into(), children: vec![], name_html: None } |
