brk_structs/structs/
opreturnindex.rs1use 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 OpReturnIndex(TypeIndex);
29
30impl From<TypeIndex> for OpReturnIndex {
31 fn from(value: TypeIndex) -> Self {
32 Self(value)
33 }
34}
35impl From<OpReturnIndex> for usize {
36 fn from(value: OpReturnIndex) -> Self {
37 Self::from(*value)
38 }
39}
40impl From<OpReturnIndex> for u64 {
41 fn from(value: OpReturnIndex) -> Self {
42 Self::from(*value)
43 }
44}
45impl From<usize> for OpReturnIndex {
46 fn from(value: usize) -> Self {
47 Self(TypeIndex::from(value))
48 }
49}
50impl Add<usize> for OpReturnIndex {
51 type Output = Self;
52 fn add(self, rhs: usize) -> Self::Output {
53 Self(*self + rhs)
54 }
55}
56impl CheckedSub<OpReturnIndex> for OpReturnIndex {
57 fn checked_sub(self, rhs: Self) -> Option<Self> {
58 self.0.checked_sub(rhs.0).map(Self)
59 }
60}
61
62impl PrintableIndex for OpReturnIndex {
63 fn to_string() -> &'static str {
64 "opreturnindex"
65 }
66
67 fn to_possible_strings() -> &'static [&'static str] {
68 &["op", "opreturn", "opreturnindex"]
69 }
70}
71
72impl std::fmt::Display for OpReturnIndex {
73 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74 self.0.fmt(f)
75 }
76}