semilattice_database/collection/
row.rs1use std::{
2 cmp::Ordering,
3 num::{NonZeroI32, NonZeroU32},
4};
5
6use serde::Serialize;
7
8#[derive(Clone, Debug, Serialize, Hash, Default)]
9pub struct CollectionRow {
10 collection_id: Option<NonZeroI32>,
11 row: Option<NonZeroU32>,
12}
13impl PartialOrd for CollectionRow {
14 #[inline(always)]
15 fn partial_cmp(&self, other: &CollectionRow) -> Option<Ordering> {
16 Some(self.cmp(other))
17 }
18}
19impl Ord for CollectionRow {
20 fn cmp(&self, other: &CollectionRow) -> Ordering {
21 if self.collection_id == other.collection_id {
22 self.row.cmp(&other.row)
23 } else if self.collection_id > other.collection_id {
24 Ordering::Greater
25 } else {
26 Ordering::Less
27 }
28 }
29}
30impl PartialEq for CollectionRow {
31 fn eq(&self, other: &CollectionRow) -> bool {
32 self.collection_id == other.collection_id && self.row == other.row
33 }
34}
35impl Eq for CollectionRow {}
36
37impl CollectionRow {
38 pub fn new(collection_id: NonZeroI32, row: NonZeroU32) -> Self {
39 Self {
40 collection_id: Some(collection_id),
41 row: Some(row),
42 }
43 }
44
45 pub fn collection_id(&self) -> NonZeroI32 {
46 self.collection_id.unwrap()
47 }
48
49 pub fn row(&self) -> NonZeroU32 {
50 self.row.unwrap()
51 }
52}