1
2use std::ops::{ Deref, Add };
3
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub struct Position(Option<usize>);
7
8impl Position {
9 pub fn null() -> Self {
10 Self( None )
11 }
12
13 pub fn opt(&self) -> Option<usize> {
14 self.0
15 }
16}
17
18impl Deref for Position {
19 type Target = Option<usize>;
20 fn deref(&self) -> &Self::Target {
21 &self.0
22 }
23}
24
25impl Add<usize> for Position {
26 type Output = usize;
27
28 fn add(self, other: usize) -> usize {
30 match self.0 {
31 Some(o) => o + other,
32 None => other - 1
33 }
34 }
35}
36
37impl From<usize> for Position {
38 fn from(n: usize) -> Self {
39 Self(Some(n))
40 }
41}