Skip to content

Commit 2102aa1

Browse files
committed
separate Clone instance
1 parent aeb4494 commit 2102aa1

File tree

1 file changed

+17
-8
lines changed
  • rust/functora-tagged/src

1 file changed

+17
-8
lines changed

rust/functora-tagged/src/lib.rs

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

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

11-
pub trait Refine<Tag>: Clone + Sized {
11+
pub trait Refine<Tag>: Sized {
1212
type RefineErrorRep: Debug + Display;
1313
fn refine(self) -> Result<Self, Self::RefineErrorRep> {
1414
Ok(self)
@@ -37,23 +37,32 @@ where
3737
}
3838
}
3939

40+
impl<Rep, Tag> Clone for Tagged<Rep, Tag>
41+
where
42+
Rep: Clone + Refine<Tag>,
43+
{
44+
fn clone(&self) -> Self {
45+
Tagged(self.rep().clone(), PhantomData)
46+
}
47+
}
48+
4049
impl<Rep, Tag> PartialEq for Tagged<Rep, Tag>
4150
where
42-
Rep: Refine<Tag> + PartialEq,
51+
Rep: PartialEq + Refine<Tag>,
4352
{
4453
fn eq(&self, other: &Self) -> bool {
4554
self.rep() == other.rep()
4655
}
4756
}
4857

4958
impl<Rep, Tag> Eq for Tagged<Rep, Tag> where
50-
Rep: Refine<Tag> + Eq
59+
Rep: Eq + Refine<Tag>
5160
{
5261
}
5362

5463
impl<Rep, Tag> PartialOrd for Tagged<Rep, Tag>
5564
where
56-
Rep: Refine<Tag> + PartialOrd,
65+
Rep: PartialOrd + Refine<Tag>,
5766
{
5867
fn partial_cmp(
5968
&self,
@@ -65,7 +74,7 @@ where
6574

6675
impl<Rep, Tag> Ord for Tagged<Rep, Tag>
6776
where
68-
Rep: Refine<Tag> + Ord,
77+
Rep: Ord + Refine<Tag>,
6978
{
7079
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
7180
self.rep().cmp(other.rep())
@@ -145,7 +154,7 @@ mod diesel_impl {
145154

146155
impl<Rep, Tag, ST> AsExpression<ST> for Tagged<Rep, Tag>
147156
where
148-
Rep: Refine<Tag> + AsExpression<ST>,
157+
Rep: Clone + Refine<Tag> + AsExpression<ST>,
149158
ST: SqlType + SingleValue,
150159
{
151160
type Expression =
@@ -157,7 +166,7 @@ mod diesel_impl {
157166

158167
impl<Rep, Tag, ST> AsExpression<ST> for &Tagged<Rep, Tag>
159168
where
160-
Rep: Refine<Tag> + AsExpression<ST>,
169+
Rep: Clone + Refine<Tag> + AsExpression<ST>,
161170
ST: SqlType + SingleValue,
162171
{
163172
type Expression =

0 commit comments

Comments
 (0)