brk_structs/structs/
p2wpkhaddressindex.rs

1use std::ops::Add;
2
3use derive_deref::{Deref, DerefMut};
4use serde::Serialize;
5use vecdb::{CheckedSub, PrintableIndex, StoredCompressed};
6use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
7
8use crate::TypeIndex;
9
10#[derive(
11    Debug,
12    PartialEq,
13    Eq,
14    PartialOrd,
15    Ord,
16    Clone,
17    Copy,
18    Deref,
19    DerefMut,
20    Default,
21    FromBytes,
22    Immutable,
23    IntoBytes,
24    KnownLayout,
25    Serialize,
26    StoredCompressed,
27)]
28pub struct P2WPKHAddressIndex(TypeIndex);
29impl From<TypeIndex> for P2WPKHAddressIndex {
30    fn from(value: TypeIndex) -> Self {
31        Self(value)
32    }
33}
34impl From<P2WPKHAddressIndex> for TypeIndex {
35    fn from(value: P2WPKHAddressIndex) -> Self {
36        value.0
37    }
38}
39impl From<P2WPKHAddressIndex> for u32 {
40    fn from(value: P2WPKHAddressIndex) -> Self {
41        Self::from(*value)
42    }
43}
44impl From<P2WPKHAddressIndex> for u64 {
45    fn from(value: P2WPKHAddressIndex) -> Self {
46        Self::from(*value)
47    }
48}
49impl From<P2WPKHAddressIndex> for usize {
50    fn from(value: P2WPKHAddressIndex) -> Self {
51        Self::from(*value)
52    }
53}
54impl From<u32> for P2WPKHAddressIndex {
55    fn from(value: u32) -> Self {
56        Self(TypeIndex::from(value))
57    }
58}
59impl From<usize> for P2WPKHAddressIndex {
60    fn from(value: usize) -> Self {
61        Self(TypeIndex::from(value))
62    }
63}
64impl Add<usize> for P2WPKHAddressIndex {
65    type Output = Self;
66    fn add(self, rhs: usize) -> Self::Output {
67        Self(*self + rhs)
68    }
69}
70impl CheckedSub<P2WPKHAddressIndex> for P2WPKHAddressIndex {
71    fn checked_sub(self, rhs: Self) -> Option<Self> {
72        self.0.checked_sub(rhs.0).map(Self)
73    }
74}
75
76impl PrintableIndex for P2WPKHAddressIndex {
77    fn to_string() -> &'static str {
78        "p2wpkhaddressindex"
79    }
80
81    fn to_possible_strings() -> &'static [&'static str] {
82        &["wpkhaddr", "p2wpkhaddr", "p2wpkhaddressindex"]
83    }
84}
85
86impl std::fmt::Display for P2WPKHAddressIndex {
87    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88        self.0.fmt(f)
89    }
90}