ccp_shared/proof/
idx.rs

1/*
2 * Copyright 2024 Fluence DAO
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use std::fmt::Display;
18use std::str::FromStr;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23#[derive(
24    Debug, Copy, Clone, Hash, Default, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize,
25)]
26#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
27#[repr(transparent)]
28#[serde(transparent)]
29pub struct ProofIdx(u64);
30
31impl ProofIdx {
32    pub fn zero() -> Self {
33        Self(0)
34    }
35
36    pub fn increment(&mut self) {
37        self.0 += 1;
38    }
39}
40
41impl Display for ProofIdx {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        write!(f, "{}", self.0)
44    }
45}
46
47impl FromStr for ProofIdx {
48    type Err = <u64 as FromStr>::Err;
49
50    fn from_str(s: &str) -> Result<Self, Self::Err> {
51        u64::from_str(s).map(ProofIdx)
52    }
53}