Implement Ord
by-hand instead of PartialOrd
for Link
This commit is contained in:
parent
ccfbfe2292
commit
329b8a312d
1 changed files with 12 additions and 6 deletions
|
@ -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 }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue