Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_o3db_sync/src/base/index.rs

1.9 KiB, 10 runs

created by r1870400018:725, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use oxedyne_fe2o3_core::prelude::*;
2
3use std::{
4 fmt::{
5 self,
6 Debug,
7 Display,
8 },
9};
10
11// Zero-based index of a storage zone. Indexes zones from 0 internally, but
12// displays from 1 for human consumption.
13new_type!(ZoneInd, usize, Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd);
14
15impl Display for ZoneInd {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 write!(f, "{:?}", self.0 + 1)
18 }
19}
20
21impl Debug for ZoneInd {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "Z{}", self.0 + 1)
24 }
25}
26
27impl ZoneInd {
28 pub fn new<I: Into<usize>>(i: I) -> Self {
29 Self(i.into())
30 }
31}
32
33// Zero-based index of a bot within its pool of worker bots. Displays from 1
34// for human consumption.
35new_type!(BotPoolInd, usize, Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd);
36
37impl Display for BotPoolInd {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 write!(f, "{:?}", self.0 + 1)
40 }
41}
42
43impl Debug for BotPoolInd {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 write!(f, "B{}", self.0 + 1)
46 }
47}
48
49impl BotPoolInd {
50 pub fn new<I: Into<usize>>(i: I) -> Self {
51 Self(i.into())
52 }
53}
54
55#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
56pub struct WorkerInd {
57 pub pool: BotPoolInd,
58 pub zone: ZoneInd,
59}
60
61impl Display for WorkerInd {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 write!(f, "{:?}{:?}", self.zone, self.pool)
64 }
65}
66
67impl WorkerInd {
68
69 pub fn new(zone: ZoneInd, pool: BotPoolInd) -> Self {
70 Self {
71 zone,
72 pool,
73 }
74 }
75
76 pub fn zind(&self) -> &ZoneInd { &self.zone }
77 pub fn bpind(&self) -> &BotPoolInd { &self.pool }
78 pub fn z(&self) -> usize { *self.zone }
79 pub fn b(&self) -> usize { *self.pool }
80
81}
82