brk_types/
emptyaddressindex.rs1use 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 Default,
13 Clone,
14 Copy,
15 PartialEq,
16 Eq,
17 PartialOrd,
18 Ord,
19 Deref,
20 Serialize,
21 Deserialize,
22 Pco,
23 JsonSchema,
24)]
25pub struct EmptyAddressIndex(TypeIndex);
26
27impl From<TypeIndex> for EmptyAddressIndex {
28 #[inline]
29 fn from(value: TypeIndex) -> Self {
30 Self(value)
31 }
32}
33
34impl From<usize> for EmptyAddressIndex {
35 #[inline]
36 fn from(value: usize) -> Self {
37 Self(TypeIndex::from(value))
38 }
39}
40impl From<u32> for EmptyAddressIndex {
41 #[inline]
42 fn from(value: u32) -> Self {
43 Self(TypeIndex::from(value))
44 }
45}
46
47impl From<EmptyAddressIndex> for usize {
48 #[inline]
49 fn from(value: EmptyAddressIndex) -> Self {
50 usize::from(value.0)
51 }
52}
53
54impl Add<usize> for EmptyAddressIndex {
55 type Output = Self;
56 fn add(self, rhs: usize) -> Self::Output {
57 Self(self.0 + rhs)
58 }
59}
60
61impl CheckedSub<EmptyAddressIndex> for EmptyAddressIndex {
62 fn checked_sub(self, rhs: Self) -> Option<Self> {
63 self.0.checked_sub(rhs.0).map(Self)
64 }
65}
66
67impl PrintableIndex for EmptyAddressIndex {
68 fn to_string() -> &'static str {
69 "emptyaddressindex"
70 }
71
72 fn to_possible_strings() -> &'static [&'static str] {
73 &["emptyaddr", "emptyaddressindex"]
74 }
75}
76
77impl std::fmt::Display for EmptyAddressIndex {
78 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 self.0.fmt(f)
80 }
81}
82
83impl Formattable for EmptyAddressIndex {
84 #[inline(always)]
85 fn may_need_escaping() -> bool {
86 false
87 }
88}