stellar_xdr/generated/
soroban_credentials.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
22#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
23#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
24#[cfg_attr(
25 all(feature = "serde", feature = "alloc"),
26 serde_with::serde_as,
27 derive(serde::Serialize, serde::Deserialize),
28 serde(rename_all = "snake_case")
29)]
30#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
31#[allow(clippy::large_enum_variant)]
32pub enum SorobanCredentials {
33 SourceAccount,
34 Address(SorobanAddressCredentials),
35 AddressV2(SorobanAddressCredentials),
36 AddressWithDelegates(SorobanAddressCredentialsWithDelegates),
37}
38
39#[cfg(feature = "alloc")]
40impl Default for SorobanCredentials {
41 fn default() -> Self {
42 Self::SourceAccount
43 }
44}
45
46impl SorobanCredentials {
47 const _VARIANTS: &[SorobanCredentialsType] = &[
48 SorobanCredentialsType::SourceAccount,
49 SorobanCredentialsType::Address,
50 SorobanCredentialsType::AddressV2,
51 SorobanCredentialsType::AddressWithDelegates,
52 ];
53 pub const VARIANTS: [SorobanCredentialsType; Self::_VARIANTS.len()] = {
54 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
55 let mut i = 1;
56 while i < Self::_VARIANTS.len() {
57 arr[i] = Self::_VARIANTS[i];
58 i += 1;
59 }
60 arr
61 };
62 const _VARIANTS_STR: &[&str] = &[
63 "SourceAccount",
64 "Address",
65 "AddressV2",
66 "AddressWithDelegates",
67 ];
68 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
69 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
70 let mut i = 1;
71 while i < Self::_VARIANTS_STR.len() {
72 arr[i] = Self::_VARIANTS_STR[i];
73 i += 1;
74 }
75 arr
76 };
77
78 #[must_use]
79 pub const fn name(&self) -> &'static str {
80 match self {
81 Self::SourceAccount => "SourceAccount",
82 Self::Address(_) => "Address",
83 Self::AddressV2(_) => "AddressV2",
84 Self::AddressWithDelegates(_) => "AddressWithDelegates",
85 }
86 }
87
88 #[must_use]
89 pub const fn discriminant(&self) -> SorobanCredentialsType {
90 #[allow(clippy::match_same_arms)]
91 match self {
92 Self::SourceAccount => SorobanCredentialsType::SourceAccount,
93 Self::Address(_) => SorobanCredentialsType::Address,
94 Self::AddressV2(_) => SorobanCredentialsType::AddressV2,
95 Self::AddressWithDelegates(_) => SorobanCredentialsType::AddressWithDelegates,
96 }
97 }
98
99 #[must_use]
100 pub const fn variants() -> [SorobanCredentialsType; Self::_VARIANTS.len()] {
101 Self::VARIANTS
102 }
103}
104
105impl Name for SorobanCredentials {
106 #[must_use]
107 fn name(&self) -> &'static str {
108 Self::name(self)
109 }
110}
111
112impl Discriminant<SorobanCredentialsType> for SorobanCredentials {
113 #[must_use]
114 fn discriminant(&self) -> SorobanCredentialsType {
115 Self::discriminant(self)
116 }
117}
118
119impl Variants<SorobanCredentialsType> for SorobanCredentials {
120 fn variants() -> slice::Iter<'static, SorobanCredentialsType> {
121 Self::VARIANTS.iter()
122 }
123}
124
125impl Union<SorobanCredentialsType> for SorobanCredentials {}
126
127impl ReadXdr for SorobanCredentials {
128 #[cfg(feature = "std")]
129 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
130 r.with_limited_depth(|r| {
131 let dv: SorobanCredentialsType = <SorobanCredentialsType as ReadXdr>::read_xdr(r)?;
132 #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
133 let v = match dv {
134 SorobanCredentialsType::SourceAccount => Self::SourceAccount,
135 SorobanCredentialsType::Address => {
136 Self::Address(SorobanAddressCredentials::read_xdr(r)?)
137 }
138 SorobanCredentialsType::AddressV2 => {
139 Self::AddressV2(SorobanAddressCredentials::read_xdr(r)?)
140 }
141 SorobanCredentialsType::AddressWithDelegates => {
142 Self::AddressWithDelegates(SorobanAddressCredentialsWithDelegates::read_xdr(r)?)
143 }
144 #[allow(unreachable_patterns)]
145 _ => return Err(Error::Invalid),
146 };
147 Ok(v)
148 })
149 }
150}
151
152impl WriteXdr for SorobanCredentials {
153 #[cfg(feature = "std")]
154 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
155 w.with_limited_depth(|w| {
156 self.discriminant().write_xdr(w)?;
157 #[allow(clippy::match_same_arms)]
158 match self {
159 Self::SourceAccount => ().write_xdr(w)?,
160 Self::Address(v) => v.write_xdr(w)?,
161 Self::AddressV2(v) => v.write_xdr(w)?,
162 Self::AddressWithDelegates(v) => v.write_xdr(w)?,
163 };
164 Ok(())
165 })
166 }
167}