Skip to content

Commit 5d265ef

Browse files
committed
separate instances for Eq, PartialEr, Ord, PartialOrd
1 parent 9f2560c commit 5d265ef

File tree

1 file changed

+37
-4
lines changed
  • rust/functora-tagged/src

1 file changed

+37
-4
lines changed

rust/functora-tagged/src/lib.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ use std::marker::PhantomData;
33
use std::str::FromStr;
44
use thiserror::Error;
55

6-
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Debug)]
6+
#[derive(Clone, Debug)]
77
pub struct Tagged<Rep, Tag>(Rep, PhantomData<Tag>)
88
where
99
Rep: Refine<Tag>;
1010

11-
pub trait Refine<Tag>:
12-
Eq + PartialEq + Ord + PartialOrd + Clone + Debug
13-
{
11+
pub trait Refine<Tag>: Clone + Sized {
1412
type RefineErrorRep: Debug + Display;
1513
fn refine(self) -> Result<Self, Self::RefineErrorRep> {
1614
Ok(self)
@@ -39,6 +37,41 @@ where
3937
}
4038
}
4139

40+
impl<Rep, Tag> PartialEq for Tagged<Rep, Tag>
41+
where
42+
Rep: Refine<Tag> + PartialEq,
43+
{
44+
fn eq(&self, other: &Self) -> bool {
45+
self.0 == other.0
46+
}
47+
}
48+
49+
impl<Rep, Tag> Eq for Tagged<Rep, Tag> where
50+
Rep: Refine<Tag> + Eq
51+
{
52+
}
53+
54+
impl<Rep, Tag> PartialOrd for Tagged<Rep, Tag>
55+
where
56+
Rep: Refine<Tag> + PartialOrd,
57+
{
58+
fn partial_cmp(
59+
&self,
60+
other: &Self,
61+
) -> Option<std::cmp::Ordering> {
62+
self.0.partial_cmp(&other.0)
63+
}
64+
}
65+
66+
impl<Rep, Tag> Ord for Tagged<Rep, Tag>
67+
where
68+
Rep: Refine<Tag> + Ord,
69+
{
70+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
71+
self.0.cmp(&other.0)
72+
}
73+
}
74+
4275
#[derive(Debug, Error)]
4376
pub enum ParseError<Rep, Tag>
4477
where

0 commit comments

Comments
 (0)