sellapp-sdk 0.1.1

Official Rust SDK for the SellApp API: manage products, orders, subscriptions, and customers.
// This file is auto-generated by oagen. Do not edit.

use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Provider {
    Manual,
    MercadoPago,
    Nmi,
    Mollie,
    Paypal,
    Razorpay,
    Square,
    Stripe,
    Null,
    /// Wire value not recognized by this SDK version. The original
    /// string is preserved verbatim. SellApp may add new enum values
    /// server-side; matching on this variant lets callers handle
    /// forward-compatible values without panicking.
    Unknown(String),
}

impl Provider {
    /// Canonical wire string for this value. For [`Self::Unknown`] returns the
    /// original wire value as received from the API.
    #[allow(deprecated)]
    pub fn as_str(&self) -> &str {
        match self {
            Self::Manual => "manual",
            Self::MercadoPago => "mercado_pago",
            Self::Nmi => "nmi",
            Self::Mollie => "mollie",
            Self::Paypal => "paypal",
            Self::Razorpay => "razorpay",
            Self::Square => "square",
            Self::Stripe => "stripe",
            Self::Null => "null",
            Self::Unknown(s) => s.as_str(),
        }
    }

    /// Whether this value was declared by the schema used to generate the SDK.
    pub fn is_known(&self) -> bool {
        !matches!(self, Self::Unknown(_))
    }
}

impl fmt::Display for Provider {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

impl AsRef<str> for Provider {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl FromStr for Provider {
    type Err = std::convert::Infallible;
    #[allow(deprecated)]
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "manual" => Self::Manual,
            "mercado_pago" => Self::MercadoPago,
            "nmi" => Self::Nmi,
            "mollie" => Self::Mollie,
            "paypal" => Self::Paypal,
            "razorpay" => Self::Razorpay,
            "square" => Self::Square,
            "stripe" => Self::Stripe,
            "null" => Self::Null,
            other => Self::Unknown(other.to_string()),
        })
    }
}

impl From<String> for Provider {
    fn from(s: String) -> Self {
        // Reuse the original `String` allocation in the fallback branch.
        match Self::from_str(&s) {
            Ok(Self::Unknown(_)) => Self::Unknown(s),
            Ok(other) => other,
        }
    }
}

impl From<&str> for Provider {
    fn from(s: &str) -> Self {
        Self::from_str(s).unwrap_or_else(|_| Self::Unknown(s.to_string()))
    }
}

impl Serialize for Provider {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for Provider {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}