#[allow(unused_imports, clippy::wildcard_imports)]
use super::*;
#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(
all(feature = "serde", feature = "alloc"),
serde_with::serde_as,
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "snake_case")
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[allow(clippy::large_enum_variant)]
pub enum InflationResult {
Success(VecM<InflationPayout>),
NotTime,
}
#[cfg(feature = "alloc")]
impl Default for InflationResult {
fn default() -> Self {
Self::Success(VecM::<InflationPayout>::default())
}
}
impl InflationResult {
const _VARIANTS: &[InflationResultCode] =
&[InflationResultCode::Success, InflationResultCode::NotTime];
pub const VARIANTS: [InflationResultCode; Self::_VARIANTS.len()] = {
let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
let mut i = 1;
while i < Self::_VARIANTS.len() {
arr[i] = Self::_VARIANTS[i];
i += 1;
}
arr
};
const _VARIANTS_STR: &[&str] = &["Success", "NotTime"];
pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
let mut i = 1;
while i < Self::_VARIANTS_STR.len() {
arr[i] = Self::_VARIANTS_STR[i];
i += 1;
}
arr
};
#[must_use]
pub const fn name(&self) -> &'static str {
match self {
Self::Success(_) => "Success",
Self::NotTime => "NotTime",
}
}
#[must_use]
pub const fn discriminant(&self) -> InflationResultCode {
#[allow(clippy::match_same_arms)]
match self {
Self::Success(_) => InflationResultCode::Success,
Self::NotTime => InflationResultCode::NotTime,
}
}
#[must_use]
pub const fn variants() -> [InflationResultCode; Self::_VARIANTS.len()] {
Self::VARIANTS
}
}
impl Name for InflationResult {
#[must_use]
fn name(&self) -> &'static str {
Self::name(self)
}
}
impl Discriminant<InflationResultCode> for InflationResult {
#[must_use]
fn discriminant(&self) -> InflationResultCode {
Self::discriminant(self)
}
}
impl Variants<InflationResultCode> for InflationResult {
fn variants() -> slice::Iter<'static, InflationResultCode> {
Self::VARIANTS.iter()
}
}
impl Union<InflationResultCode> for InflationResult {}
impl ReadXdr for InflationResult {
#[cfg(feature = "std")]
fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
r.with_limited_depth(|r| {
let dv: InflationResultCode = <InflationResultCode as ReadXdr>::read_xdr(r)?;
#[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
let v = match dv {
InflationResultCode::Success => {
Self::Success(VecM::<InflationPayout>::read_xdr(r)?)
}
InflationResultCode::NotTime => Self::NotTime,
#[allow(unreachable_patterns)]
_ => return Err(Error::Invalid),
};
Ok(v)
})
}
}
impl WriteXdr for InflationResult {
#[cfg(feature = "std")]
fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
w.with_limited_depth(|w| {
self.discriminant().write_xdr(w)?;
#[allow(clippy::match_same_arms)]
match self {
Self::Success(v) => v.write_xdr(w)?,
Self::NotTime => ().write_xdr(w)?,
};
Ok(())
})
}
}