algae_mmr/cmp/
position.rs1use decanter::prelude::Hashable;
7use serde::{Deserialize, Serialize};
8
9#[derive(
10 Clone, Debug, Default, Deserialize, Eq, Hash, Hashable, Ord, PartialEq, PartialOrd, Serialize,
11)]
12pub struct Position {
13 pub height: usize,
14 pub index: usize,
15}
16
17impl Position {
18 pub fn new(height: usize, index: usize) -> Self {
19 Self { height, index }
20 }
21 pub fn height(&self) -> usize {
22 self.height
23 }
24 pub fn index(&self) -> usize {
25 self.index
26 }
27}
28
29impl From<(usize, usize)> for Position {
30 fn from(data: (usize, usize)) -> Self {
31 Self::new(data.0, data.1)
32 }
33}
34
35impl std::fmt::Display for Position {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 write!(f, "{}", serde_json::to_string(&self).unwrap())
38 }
39}