Skip to content

Commit

Permalink
Merge pull request #537 from mzeitlin11/from_str_tweaks
Browse files Browse the repository at this point in the history
Enum generated FromStr improvements
  • Loading branch information
mzeitlin11 committed May 4, 2024
2 parents 4f29e69 + 001d7dd commit ba6f20d
Show file tree
Hide file tree
Showing 411 changed files with 3,162 additions and 3,197 deletions.
Expand Up @@ -188,7 +188,7 @@ impl CreateBillingPortalConfigurationFeaturesCustomerUpdateAllowedUpdates {
}

impl std::str::FromStr for CreateBillingPortalConfigurationFeaturesCustomerUpdateAllowedUpdates {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateBillingPortalConfigurationFeaturesCustomerUpdateAllowedUpdates::*;
match s {
Expand All @@ -198,7 +198,7 @@ impl std::str::FromStr for CreateBillingPortalConfigurationFeaturesCustomerUpdat
"phone" => Ok(Phone),
"shipping" => Ok(Shipping),
"tax_id" => Ok(TaxId),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -325,7 +325,7 @@ impl CreateBillingPortalConfigurationFeaturesSubscriptionCancelCancellationReaso
impl std::str::FromStr
for CreateBillingPortalConfigurationFeaturesSubscriptionCancelCancellationReasonOptions
{
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateBillingPortalConfigurationFeaturesSubscriptionCancelCancellationReasonOptions::*;
match s {
Expand All @@ -337,7 +337,7 @@ impl std::str::FromStr
"too_complex" => Ok(TooComplex),
"too_expensive" => Ok(TooExpensive),
"unused" => Ok(Unused),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -393,13 +393,13 @@ impl CreateBillingPortalConfigurationFeaturesSubscriptionCancelMode {
}

impl std::str::FromStr for CreateBillingPortalConfigurationFeaturesSubscriptionCancelMode {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateBillingPortalConfigurationFeaturesSubscriptionCancelMode::*;
match s {
"at_period_end" => Ok(AtPeriodEnd),
"immediately" => Ok(Immediately),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -459,14 +459,14 @@ impl CreateBillingPortalConfigurationFeaturesSubscriptionCancelProrationBehavior
impl std::str::FromStr
for CreateBillingPortalConfigurationFeaturesSubscriptionCancelProrationBehavior
{
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateBillingPortalConfigurationFeaturesSubscriptionCancelProrationBehavior::*;
match s {
"always_invoice" => Ok(AlwaysInvoice),
"create_prorations" => Ok(CreateProrations),
"none" => Ok(None),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -551,14 +551,14 @@ impl CreateBillingPortalConfigurationFeaturesSubscriptionUpdateDefaultAllowedUpd
impl std::str::FromStr
for CreateBillingPortalConfigurationFeaturesSubscriptionUpdateDefaultAllowedUpdates
{
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateBillingPortalConfigurationFeaturesSubscriptionUpdateDefaultAllowedUpdates::*;
match s {
"price" => Ok(Price),
"promotion_code" => Ok(PromotionCode),
"quantity" => Ok(Quantity),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -619,14 +619,14 @@ impl CreateBillingPortalConfigurationFeaturesSubscriptionUpdateProrationBehavior
impl std::str::FromStr
for CreateBillingPortalConfigurationFeaturesSubscriptionUpdateProrationBehavior
{
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateBillingPortalConfigurationFeaturesSubscriptionUpdateProrationBehavior::*;
match s {
"always_invoice" => Ok(AlwaysInvoice),
"create_prorations" => Ok(CreateProrations),
"none" => Ok(None),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -806,7 +806,7 @@ impl UpdateBillingPortalConfigurationFeaturesCustomerUpdateAllowedUpdates {
}

impl std::str::FromStr for UpdateBillingPortalConfigurationFeaturesCustomerUpdateAllowedUpdates {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use UpdateBillingPortalConfigurationFeaturesCustomerUpdateAllowedUpdates::*;
match s {
Expand All @@ -816,7 +816,7 @@ impl std::str::FromStr for UpdateBillingPortalConfigurationFeaturesCustomerUpdat
"phone" => Ok(Phone),
"shipping" => Ok(Shipping),
"tax_id" => Ok(TaxId),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -943,7 +943,7 @@ impl UpdateBillingPortalConfigurationFeaturesSubscriptionCancelCancellationReaso
impl std::str::FromStr
for UpdateBillingPortalConfigurationFeaturesSubscriptionCancelCancellationReasonOptions
{
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use UpdateBillingPortalConfigurationFeaturesSubscriptionCancelCancellationReasonOptions::*;
match s {
Expand All @@ -955,7 +955,7 @@ impl std::str::FromStr
"too_complex" => Ok(TooComplex),
"too_expensive" => Ok(TooExpensive),
"unused" => Ok(Unused),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -1011,13 +1011,13 @@ impl UpdateBillingPortalConfigurationFeaturesSubscriptionCancelMode {
}

impl std::str::FromStr for UpdateBillingPortalConfigurationFeaturesSubscriptionCancelMode {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use UpdateBillingPortalConfigurationFeaturesSubscriptionCancelMode::*;
match s {
"at_period_end" => Ok(AtPeriodEnd),
"immediately" => Ok(Immediately),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -1077,14 +1077,14 @@ impl UpdateBillingPortalConfigurationFeaturesSubscriptionCancelProrationBehavior
impl std::str::FromStr
for UpdateBillingPortalConfigurationFeaturesSubscriptionCancelProrationBehavior
{
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use UpdateBillingPortalConfigurationFeaturesSubscriptionCancelProrationBehavior::*;
match s {
"always_invoice" => Ok(AlwaysInvoice),
"create_prorations" => Ok(CreateProrations),
"none" => Ok(None),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -1169,14 +1169,14 @@ impl UpdateBillingPortalConfigurationFeaturesSubscriptionUpdateDefaultAllowedUpd
impl std::str::FromStr
for UpdateBillingPortalConfigurationFeaturesSubscriptionUpdateDefaultAllowedUpdates
{
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use UpdateBillingPortalConfigurationFeaturesSubscriptionUpdateDefaultAllowedUpdates::*;
match s {
"price" => Ok(Price),
"promotion_code" => Ok(PromotionCode),
"quantity" => Ok(Quantity),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -1237,14 +1237,14 @@ impl UpdateBillingPortalConfigurationFeaturesSubscriptionUpdateProrationBehavior
impl std::str::FromStr
for UpdateBillingPortalConfigurationFeaturesSubscriptionUpdateProrationBehavior
{
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use UpdateBillingPortalConfigurationFeaturesSubscriptionUpdateProrationBehavior::*;
match s {
"always_invoice" => Ok(AlwaysInvoice),
"create_prorations" => Ok(CreateProrations),
"none" => Ok(None),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions generated/stripe_billing/src/billing_portal_session/requests.rs
Expand Up @@ -133,14 +133,14 @@ impl CreateBillingPortalSessionFlowDataAfterCompletionType {
}

impl std::str::FromStr for CreateBillingPortalSessionFlowDataAfterCompletionType {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateBillingPortalSessionFlowDataAfterCompletionType::*;
match s {
"hosted_confirmation" => Ok(HostedConfirmation),
"portal_homepage" => Ok(PortalHomepage),
"redirect" => Ok(Redirect),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -232,12 +232,12 @@ impl CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType {
}

impl std::str::FromStr for CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType::*;
match s {
"coupon_offer" => Ok(CouponOffer),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -359,15 +359,15 @@ impl CreateBillingPortalSessionFlowDataType {
}

impl std::str::FromStr for CreateBillingPortalSessionFlowDataType {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateBillingPortalSessionFlowDataType::*;
match s {
"payment_method_update" => Ok(PaymentMethodUpdate),
"subscription_cancel" => Ok(SubscriptionCancel),
"subscription_update" => Ok(SubscriptionUpdate),
"subscription_update_confirm" => Ok(SubscriptionUpdateConfirm),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions generated/stripe_billing/src/billing_portal_session/types.rs
Expand Up @@ -317,7 +317,7 @@ impl BillingPortalSessionLocale {
}

impl std::str::FromStr for BillingPortalSessionLocale {
type Err = ();
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use BillingPortalSessionLocale::*;
match s {
Expand Down Expand Up @@ -368,7 +368,7 @@ impl std::str::FromStr for BillingPortalSessionLocale {
"zh" => Ok(Zh),
"zh-HK" => Ok(ZhMinusHk),
"zh-TW" => Ok(ZhMinusTw),
_ => Err(()),
_ => Ok(Self::Unknown),
}
}
}
Expand Down Expand Up @@ -400,9 +400,7 @@ impl miniserde::Deserialize for BillingPortalSessionLocale {
impl miniserde::de::Visitor for crate::Place<BillingPortalSessionLocale> {
fn string(&mut self, s: &str) -> miniserde::Result<()> {
use std::str::FromStr;
self.out = Some(
BillingPortalSessionLocale::from_str(s).unwrap_or(BillingPortalSessionLocale::Unknown),
);
self.out = Some(BillingPortalSessionLocale::from_str(s).unwrap());
Ok(())
}
}
Expand All @@ -413,6 +411,6 @@ impl<'de> serde::Deserialize<'de> for BillingPortalSessionLocale {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
use std::str::FromStr;
let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
Ok(Self::from_str(&s).unwrap_or(Self::Unknown))
Ok(Self::from_str(&s).unwrap())
}
}
12 changes: 6 additions & 6 deletions generated/stripe_billing/src/credit_note/requests.rs
Expand Up @@ -195,13 +195,13 @@ impl PreviewCreditNoteLinesType {
}

impl std::str::FromStr for PreviewCreditNoteLinesType {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use PreviewCreditNoteLinesType::*;
match s {
"custom_line_item" => Ok(CustomLineItem),
"invoice_line_item" => Ok(InvoiceLineItem),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -389,13 +389,13 @@ impl PreviewLinesCreditNoteLinesType {
}

impl std::str::FromStr for PreviewLinesCreditNoteLinesType {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use PreviewLinesCreditNoteLinesType::*;
match s {
"custom_line_item" => Ok(CustomLineItem),
"invoice_line_item" => Ok(InvoiceLineItem),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down Expand Up @@ -576,13 +576,13 @@ impl CreateCreditNoteLinesType {
}

impl std::str::FromStr for CreateCreditNoteLinesType {
type Err = ();
type Err = stripe_types::StripeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use CreateCreditNoteLinesType::*;
match s {
"custom_line_item" => Ok(CustomLineItem),
"invoice_line_item" => Ok(InvoiceLineItem),
_ => Err(()),
_ => Err(stripe_types::StripeParseError),
}
}
}
Expand Down

0 comments on commit ba6f20d

Please sign in to comment.