Skip to main content

brk_types/
unknownoutputindex.rs

1use std::ops::Add;
2
3use derive_more::{Deref, DerefMut};
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    DerefMut,
20    Default,
21    Serialize,
22    Deserialize,
23    Pco,
24    JsonSchema,
25)]
26pub struct UnknownOutputIndex(TypeIndex);
27
28impl From<TypeIndex> for UnknownOutputIndex {
29    #[inline]
30    fn from(value: TypeIndex) -> Self {
31        Self(value)
32    }
33}
34impl From<UnknownOutputIndex> for u64 {
35    #[inline]
36    fn from(value: UnknownOutputIndex) -> Self {
37        Self::from(*value)
38    }
39}
40impl From<UnknownOutputIndex> for usize {
41    #[inline]
42    fn from(value: UnknownOutputIndex) -> Self {
43        Self::from(*value)
44    }
45}
46impl From<usize> for UnknownOutputIndex {
47    #[inline]
48    fn from(value: usize) -> Self {
49        Self(TypeIndex::from(value))
50    }
51}
52impl Add<usize> for UnknownOutputIndex {
53    type Output = Self;
54    fn add(self, rhs: usize) -> Self::Output {
55        Self(*self + rhs)
56    }
57}
58impl CheckedSub<UnknownOutputIndex> for UnknownOutputIndex {
59    fn checked_sub(self, rhs: Self) -> Option<Self> {
60        self.0.checked_sub(rhs.0).map(Self)
61    }
62}
63
64impl PrintableIndex for UnknownOutputIndex {
65    fn to_string() -> &'static str {
66        "unknownoutputindex"
67    }
68
69    fn to_possible_strings() -> &'static [&'static str] {
70        &["unknownout", "unknownoutputindex"]
71    }
72}
73
74impl std::fmt::Display for UnknownOutputIndex {
75    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76        self.0.fmt(f)
77    }
78}
79
80impl Formattable for UnknownOutputIndex {
81    #[inline(always)]
82    fn may_need_escaping() -> bool {
83        false
84    }
85}