#[allow(unused_imports, clippy::wildcard_imports)]
use super::*;
#[cfg_attr(feature = "alloc", derive(Default))]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(
all(feature = "serde", feature = "alloc"),
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "snake_case")
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[repr(i32)]
pub enum PathPaymentStrictSendResultCode {
#[cfg_attr(feature = "alloc", default)]
Success = 0,
Malformed = -1,
Underfunded = -2,
SrcNoTrust = -3,
SrcNotAuthorized = -4,
NoDestination = -5,
NoTrust = -6,
NotAuthorized = -7,
LineFull = -8,
NoIssuer = -9,
TooFewOffers = -10,
OfferCrossSelf = -11,
UnderDestmin = -12,
}
impl PathPaymentStrictSendResultCode {
const _VARIANTS: &[PathPaymentStrictSendResultCode] = &[
PathPaymentStrictSendResultCode::Success,
PathPaymentStrictSendResultCode::Malformed,
PathPaymentStrictSendResultCode::Underfunded,
PathPaymentStrictSendResultCode::SrcNoTrust,
PathPaymentStrictSendResultCode::SrcNotAuthorized,
PathPaymentStrictSendResultCode::NoDestination,
PathPaymentStrictSendResultCode::NoTrust,
PathPaymentStrictSendResultCode::NotAuthorized,
PathPaymentStrictSendResultCode::LineFull,
PathPaymentStrictSendResultCode::NoIssuer,
PathPaymentStrictSendResultCode::TooFewOffers,
PathPaymentStrictSendResultCode::OfferCrossSelf,
PathPaymentStrictSendResultCode::UnderDestmin,
];
pub const VARIANTS: [PathPaymentStrictSendResultCode; 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",
"Malformed",
"Underfunded",
"SrcNoTrust",
"SrcNotAuthorized",
"NoDestination",
"NoTrust",
"NotAuthorized",
"LineFull",
"NoIssuer",
"TooFewOffers",
"OfferCrossSelf",
"UnderDestmin",
];
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::Malformed => "Malformed",
Self::Underfunded => "Underfunded",
Self::SrcNoTrust => "SrcNoTrust",
Self::SrcNotAuthorized => "SrcNotAuthorized",
Self::NoDestination => "NoDestination",
Self::NoTrust => "NoTrust",
Self::NotAuthorized => "NotAuthorized",
Self::LineFull => "LineFull",
Self::NoIssuer => "NoIssuer",
Self::TooFewOffers => "TooFewOffers",
Self::OfferCrossSelf => "OfferCrossSelf",
Self::UnderDestmin => "UnderDestmin",
}
}
#[must_use]
pub const fn variants() -> [PathPaymentStrictSendResultCode; Self::_VARIANTS.len()] {
Self::VARIANTS
}
}
impl Name for PathPaymentStrictSendResultCode {
#[must_use]
fn name(&self) -> &'static str {
Self::name(self)
}
}
impl Variants<PathPaymentStrictSendResultCode> for PathPaymentStrictSendResultCode {
fn variants() -> slice::Iter<'static, PathPaymentStrictSendResultCode> {
Self::VARIANTS.iter()
}
}
impl Enum for PathPaymentStrictSendResultCode {}
impl fmt::Display for PathPaymentStrictSendResultCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.name())
}
}
impl TryFrom<i32> for PathPaymentStrictSendResultCode {
type Error = Error;
fn try_from(i: i32) -> Result<Self, Error> {
let e = match i {
0 => PathPaymentStrictSendResultCode::Success,
-1 => PathPaymentStrictSendResultCode::Malformed,
-2 => PathPaymentStrictSendResultCode::Underfunded,
-3 => PathPaymentStrictSendResultCode::SrcNoTrust,
-4 => PathPaymentStrictSendResultCode::SrcNotAuthorized,
-5 => PathPaymentStrictSendResultCode::NoDestination,
-6 => PathPaymentStrictSendResultCode::NoTrust,
-7 => PathPaymentStrictSendResultCode::NotAuthorized,
-8 => PathPaymentStrictSendResultCode::LineFull,
-9 => PathPaymentStrictSendResultCode::NoIssuer,
-10 => PathPaymentStrictSendResultCode::TooFewOffers,
-11 => PathPaymentStrictSendResultCode::OfferCrossSelf,
-12 => PathPaymentStrictSendResultCode::UnderDestmin,
#[allow(unreachable_patterns)]
_ => return Err(Error::Invalid),
};
Ok(e)
}
}
impl From<PathPaymentStrictSendResultCode> for i32 {
#[must_use]
fn from(e: PathPaymentStrictSendResultCode) -> Self {
e as Self
}
}
impl ReadXdr for PathPaymentStrictSendResultCode {
#[cfg(feature = "std")]
fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
r.with_limited_depth(|r| {
let e = i32::read_xdr(r)?;
let v: Self = e.try_into()?;
Ok(v)
})
}
}
impl WriteXdr for PathPaymentStrictSendResultCode {
#[cfg(feature = "std")]
fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
w.with_limited_depth(|w| {
let i: i32 = (*self).into();
i.write_xdr(w)
})
}
}