1
Fork 0

Implement Ord by-hand instead of PartialOrd for Link

This commit is contained in:
Yotam Ofek 2025-03-01 21:50:43 +00:00
parent ccfbfe2292
commit 329b8a312d

View file

@ -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 }