stellar_xdr/generated/
public_key.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
16#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
17#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
18#[cfg_attr(
19 all(feature = "serde", feature = "alloc"),
20 derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr)
21)]
22#[allow(clippy::large_enum_variant)]
23pub enum PublicKey {
24 PublicKeyTypeEd25519(Uint256),
25}
26
27#[cfg(feature = "alloc")]
28impl Default for PublicKey {
29 fn default() -> Self {
30 Self::PublicKeyTypeEd25519(Uint256::default())
31 }
32}
33
34impl PublicKey {
35 const _VARIANTS: &[PublicKeyType] = &[PublicKeyType::PublicKeyTypeEd25519];
36 pub const VARIANTS: [PublicKeyType; Self::_VARIANTS.len()] = {
37 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
38 let mut i = 1;
39 while i < Self::_VARIANTS.len() {
40 arr[i] = Self::_VARIANTS[i];
41 i += 1;
42 }
43 arr
44 };
45 const _VARIANTS_STR: &[&str] = &["PublicKeyTypeEd25519"];
46 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
47 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
48 let mut i = 1;
49 while i < Self::_VARIANTS_STR.len() {
50 arr[i] = Self::_VARIANTS_STR[i];
51 i += 1;
52 }
53 arr
54 };
55
56 #[must_use]
57 pub const fn name(&self) -> &'static str {
58 match self {
59 Self::PublicKeyTypeEd25519(_) => "PublicKeyTypeEd25519",
60 }
61 }
62
63 #[must_use]
64 pub const fn discriminant(&self) -> PublicKeyType {
65 #[allow(clippy::match_same_arms)]
66 match self {
67 Self::PublicKeyTypeEd25519(_) => PublicKeyType::PublicKeyTypeEd25519,
68 }
69 }
70
71 #[must_use]
72 pub const fn variants() -> [PublicKeyType; Self::_VARIANTS.len()] {
73 Self::VARIANTS
74 }
75}
76
77impl Name for PublicKey {
78 #[must_use]
79 fn name(&self) -> &'static str {
80 Self::name(self)
81 }
82}
83
84impl Discriminant<PublicKeyType> for PublicKey {
85 #[must_use]
86 fn discriminant(&self) -> PublicKeyType {
87 Self::discriminant(self)
88 }
89}
90
91impl Variants<PublicKeyType> for PublicKey {
92 fn variants() -> slice::Iter<'static, PublicKeyType> {
93 Self::VARIANTS.iter()
94 }
95}
96
97impl Union<PublicKeyType> for PublicKey {}
98
99impl ReadXdr for PublicKey {
100 #[cfg(feature = "std")]
101 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
102 r.with_limited_depth(|r| {
103 let dv: PublicKeyType = <PublicKeyType as ReadXdr>::read_xdr(r)?;
104 #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
105 let v = match dv {
106 PublicKeyType::PublicKeyTypeEd25519 => {
107 Self::PublicKeyTypeEd25519(Uint256::read_xdr(r)?)
108 }
109 #[allow(unreachable_patterns)]
110 _ => return Err(Error::Invalid),
111 };
112 Ok(v)
113 })
114 }
115}
116
117impl WriteXdr for PublicKey {
118 #[cfg(feature = "std")]
119 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
120 w.with_limited_depth(|w| {
121 self.discriminant().write_xdr(w)?;
122 #[allow(clippy::match_same_arms)]
123 match self {
124 Self::PublicKeyTypeEd25519(v) => v.write_xdr(w)?,
125 };
126 Ok(())
127 })
128 }
129}