brk_structs/structs/
loadedaddressindex.rs1use std::ops::Add;
2
3use derive_deref::Deref;
4use serde::Serialize;
5use vecdb::{CheckedSub, Printable};
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 Default,
20 FromBytes,
21 Immutable,
22 IntoBytes,
23 KnownLayout,
24 Serialize,
25)]
26pub struct LoadedAddressIndex(TypeIndex);
27
28impl From<TypeIndex> for LoadedAddressIndex {
29 fn from(value: TypeIndex) -> Self {
30 Self(value)
31 }
32}
33
34impl From<usize> for LoadedAddressIndex {
35 fn from(value: usize) -> Self {
36 Self(TypeIndex::from(value))
37 }
38}
39impl From<LoadedAddressIndex> for usize {
40 fn from(value: LoadedAddressIndex) -> Self {
41 usize::from(value.0)
42 }
43}
44impl From<LoadedAddressIndex> for u32 {
45 fn from(value: LoadedAddressIndex) -> Self {
46 u32::from(value.0)
47 }
48}
49impl Add<usize> for LoadedAddressIndex {
50 type Output = Self;
51 fn add(self, rhs: usize) -> Self::Output {
52 Self(self.0 + rhs)
53 }
54}
55impl CheckedSub<LoadedAddressIndex> for LoadedAddressIndex {
56 fn checked_sub(self, rhs: Self) -> Option<Self> {
57 self.0.checked_sub(rhs.0).map(Self)
58 }
59}
60impl Printable for LoadedAddressIndex {
61 fn to_string() -> &'static str {
62 "loadedaddressindex"
63 }
64
65 fn to_possible_strings() -> &'static [&'static str] {
66 &["loadedaddr", "loadedaddressindex"]
67 }
68}