Skip to main content

brk_types/
fundedaddressindex.rs

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