Skip to content

Commit 4a54ee2

Browse files
committed
Implemented more std traits for ForeignModel
1 parent bf2fc00 commit 4a54ee2

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Since 0.9.3
22
-----------
3-
- Implemented like and ilike on ForeignModel
3+
- Implemented like and ilike for ForeignModel
4+
- Implemented Display, Ord, PartialOrd, Eq, PartialEq and Hash for ForeignModel
45

56
Notes for publishing
67
--------------------

src/fields/types/foreign_model.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! The [ForeignModel] field type
22
3+
use std::cmp::Ordering;
34
use std::fmt;
5+
use std::hash::{Hash, Hasher};
46

57
use rorm_db::Executor;
68

@@ -64,6 +66,14 @@ impl<FF: SingleColumnField> ForeignModelByField<FF> {
6466
}
6567
}
6668

69+
impl<FF: SingleColumnField> fmt::Display for ForeignModelByField<FF>
70+
where
71+
FF::Type: fmt::Display,
72+
{
73+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74+
fmt::Display::fmt(&self.0, f)
75+
}
76+
}
6777
impl<FF: SingleColumnField> fmt::Debug for ForeignModelByField<FF>
6878
where
6979
FF::Type: fmt::Debug,
@@ -81,3 +91,36 @@ where
8191
}
8292
}
8393
impl<FF: SingleColumnField> Copy for ForeignModelByField<FF> where FF::Type: Copy {}
94+
impl<FF: SingleColumnField> PartialOrd for ForeignModelByField<FF>
95+
where
96+
FF::Type: PartialOrd,
97+
{
98+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
99+
self.0.partial_cmp(&other.0)
100+
}
101+
}
102+
impl<FF: SingleColumnField> Ord for ForeignModelByField<FF>
103+
where
104+
FF::Type: Ord,
105+
{
106+
fn cmp(&self, other: &Self) -> Ordering {
107+
self.0.cmp(&other.0)
108+
}
109+
}
110+
impl<FF: SingleColumnField> PartialEq for ForeignModelByField<FF>
111+
where
112+
FF::Type: PartialEq,
113+
{
114+
fn eq(&self, other: &Self) -> bool {
115+
self.0.eq(&other.0)
116+
}
117+
}
118+
impl<FF: SingleColumnField> Eq for ForeignModelByField<FF> where FF::Type: Eq {}
119+
impl<FF: SingleColumnField> Hash for ForeignModelByField<FF>
120+
where
121+
FF::Type: Hash,
122+
{
123+
fn hash<H: Hasher>(&self, state: &mut H) {
124+
self.0.hash(state)
125+
}
126+
}

0 commit comments

Comments
 (0)