#[derive(Clone)]
#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct TaxRate {
pub active: bool,
pub country: Option<String>,
pub created: stripe_types::Timestamp,
pub description: Option<String>,
pub display_name: String,
pub effective_percentage: Option<f64>,
pub flat_amount: Option<stripe_shared::TaxRateFlatAmount>,
pub id: stripe_shared::TaxRateId,
pub inclusive: bool,
pub jurisdiction: Option<String>,
pub jurisdiction_level: Option<TaxRateJurisdictionLevel>,
pub livemode: bool,
pub metadata: Option<std::collections::HashMap<String, String>>,
pub percentage: f64,
pub rate_type: Option<TaxRateRateType>,
pub state: Option<String>,
pub tax_type: Option<stripe_shared::TaxRateTaxType>,
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for TaxRate {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("TaxRate").finish_non_exhaustive()
}
}
#[doc(hidden)]
pub struct TaxRateBuilder {
active: Option<bool>,
country: Option<Option<String>>,
created: Option<stripe_types::Timestamp>,
description: Option<Option<String>>,
display_name: Option<String>,
effective_percentage: Option<Option<f64>>,
flat_amount: Option<Option<stripe_shared::TaxRateFlatAmount>>,
id: Option<stripe_shared::TaxRateId>,
inclusive: Option<bool>,
jurisdiction: Option<Option<String>>,
jurisdiction_level: Option<Option<TaxRateJurisdictionLevel>>,
livemode: Option<bool>,
metadata: Option<Option<std::collections::HashMap<String, String>>>,
percentage: Option<f64>,
rate_type: Option<Option<TaxRateRateType>>,
state: Option<Option<String>>,
tax_type: Option<Option<stripe_shared::TaxRateTaxType>>,
}
#[allow(
unused_variables,
irrefutable_let_patterns,
clippy::let_unit_value,
clippy::match_single_binding,
clippy::single_match
)]
const _: () = {
use miniserde::de::{Map, Visitor};
use miniserde::json::Value;
use miniserde::{Deserialize, Result, make_place};
use stripe_types::miniserde_helpers::FromValueOpt;
use stripe_types::{MapBuilder, ObjectDeser};
make_place!(Place);
impl Deserialize for TaxRate {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
Place::new(out)
}
}
struct Builder<'a> {
out: &'a mut Option<TaxRate>,
builder: TaxRateBuilder,
}
impl Visitor for Place<TaxRate> {
fn map(&mut self) -> Result<Box<dyn Map + '_>> {
Ok(Box::new(Builder { out: &mut self.out, builder: TaxRateBuilder::deser_default() }))
}
}
impl MapBuilder for TaxRateBuilder {
type Out = TaxRate;
fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
Ok(match k {
"active" => Deserialize::begin(&mut self.active),
"country" => Deserialize::begin(&mut self.country),
"created" => Deserialize::begin(&mut self.created),
"description" => Deserialize::begin(&mut self.description),
"display_name" => Deserialize::begin(&mut self.display_name),
"effective_percentage" => Deserialize::begin(&mut self.effective_percentage),
"flat_amount" => Deserialize::begin(&mut self.flat_amount),
"id" => Deserialize::begin(&mut self.id),
"inclusive" => Deserialize::begin(&mut self.inclusive),
"jurisdiction" => Deserialize::begin(&mut self.jurisdiction),
"jurisdiction_level" => Deserialize::begin(&mut self.jurisdiction_level),
"livemode" => Deserialize::begin(&mut self.livemode),
"metadata" => Deserialize::begin(&mut self.metadata),
"percentage" => Deserialize::begin(&mut self.percentage),
"rate_type" => Deserialize::begin(&mut self.rate_type),
"state" => Deserialize::begin(&mut self.state),
"tax_type" => Deserialize::begin(&mut self.tax_type),
_ => <dyn Visitor>::ignore(),
})
}
fn deser_default() -> Self {
Self {
active: None,
country: Some(None),
created: None,
description: Some(None),
display_name: None,
effective_percentage: Some(None),
flat_amount: Some(None),
id: None,
inclusive: None,
jurisdiction: Some(None),
jurisdiction_level: Some(None),
livemode: None,
metadata: Some(None),
percentage: None,
rate_type: Some(None),
state: Some(None),
tax_type: Some(None),
}
}
fn take_out(&mut self) -> Option<Self::Out> {
let (
Some(active),
Some(country),
Some(created),
Some(description),
Some(display_name),
Some(effective_percentage),
Some(flat_amount),
Some(id),
Some(inclusive),
Some(jurisdiction),
Some(jurisdiction_level),
Some(livemode),
Some(metadata),
Some(percentage),
Some(rate_type),
Some(state),
Some(tax_type),
) = (
self.active,
self.country.take(),
self.created,
self.description.take(),
self.display_name.take(),
self.effective_percentage,
self.flat_amount.take(),
self.id.take(),
self.inclusive,
self.jurisdiction.take(),
self.jurisdiction_level.take(),
self.livemode,
self.metadata.take(),
self.percentage,
self.rate_type.take(),
self.state.take(),
self.tax_type.take(),
)
else {
return None;
};
Some(Self::Out {
active,
country,
created,
description,
display_name,
effective_percentage,
flat_amount,
id,
inclusive,
jurisdiction,
jurisdiction_level,
livemode,
metadata,
percentage,
rate_type,
state,
tax_type,
})
}
}
impl Map for Builder<'_> {
fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
self.builder.key(k)
}
fn finish(&mut self) -> Result<()> {
*self.out = self.builder.take_out();
Ok(())
}
}
impl ObjectDeser for TaxRate {
type Builder = TaxRateBuilder;
}
impl FromValueOpt for TaxRate {
fn from_value(v: Value) -> Option<Self> {
let Value::Object(obj) = v else {
return None;
};
let mut b = TaxRateBuilder::deser_default();
for (k, v) in obj {
match k.as_str() {
"active" => b.active = FromValueOpt::from_value(v),
"country" => b.country = FromValueOpt::from_value(v),
"created" => b.created = FromValueOpt::from_value(v),
"description" => b.description = FromValueOpt::from_value(v),
"display_name" => b.display_name = FromValueOpt::from_value(v),
"effective_percentage" => b.effective_percentage = FromValueOpt::from_value(v),
"flat_amount" => b.flat_amount = FromValueOpt::from_value(v),
"id" => b.id = FromValueOpt::from_value(v),
"inclusive" => b.inclusive = FromValueOpt::from_value(v),
"jurisdiction" => b.jurisdiction = FromValueOpt::from_value(v),
"jurisdiction_level" => b.jurisdiction_level = FromValueOpt::from_value(v),
"livemode" => b.livemode = FromValueOpt::from_value(v),
"metadata" => b.metadata = FromValueOpt::from_value(v),
"percentage" => b.percentage = FromValueOpt::from_value(v),
"rate_type" => b.rate_type = FromValueOpt::from_value(v),
"state" => b.state = FromValueOpt::from_value(v),
"tax_type" => b.tax_type = FromValueOpt::from_value(v),
_ => {}
}
}
b.take_out()
}
}
};
#[cfg(feature = "serialize")]
impl serde::Serialize for TaxRate {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
use serde::ser::SerializeStruct;
let mut s = s.serialize_struct("TaxRate", 18)?;
s.serialize_field("active", &self.active)?;
s.serialize_field("country", &self.country)?;
s.serialize_field("created", &self.created)?;
s.serialize_field("description", &self.description)?;
s.serialize_field("display_name", &self.display_name)?;
s.serialize_field("effective_percentage", &self.effective_percentage)?;
s.serialize_field("flat_amount", &self.flat_amount)?;
s.serialize_field("id", &self.id)?;
s.serialize_field("inclusive", &self.inclusive)?;
s.serialize_field("jurisdiction", &self.jurisdiction)?;
s.serialize_field("jurisdiction_level", &self.jurisdiction_level)?;
s.serialize_field("livemode", &self.livemode)?;
s.serialize_field("metadata", &self.metadata)?;
s.serialize_field("percentage", &self.percentage)?;
s.serialize_field("rate_type", &self.rate_type)?;
s.serialize_field("state", &self.state)?;
s.serialize_field("tax_type", &self.tax_type)?;
s.serialize_field("object", "tax_rate")?;
s.end()
}
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum TaxRateJurisdictionLevel {
City,
Country,
County,
District,
Multiple,
State,
Unknown(String),
}
impl TaxRateJurisdictionLevel {
pub fn as_str(&self) -> &str {
use TaxRateJurisdictionLevel::*;
match self {
City => "city",
Country => "country",
County => "county",
District => "district",
Multiple => "multiple",
State => "state",
Unknown(v) => v,
}
}
}
impl std::str::FromStr for TaxRateJurisdictionLevel {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use TaxRateJurisdictionLevel::*;
match s {
"city" => Ok(City),
"country" => Ok(Country),
"county" => Ok(County),
"district" => Ok(District),
"multiple" => Ok(Multiple),
"state" => Ok(State),
v => {
tracing::warn!("Unknown value '{}' for enum '{}'", v, "TaxRateJurisdictionLevel");
Ok(Unknown(v.to_owned()))
}
}
}
}
impl std::fmt::Display for TaxRateJurisdictionLevel {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(not(feature = "redact-generated-debug"))]
impl std::fmt::Debug for TaxRateJurisdictionLevel {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for TaxRateJurisdictionLevel {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct(stringify!(TaxRateJurisdictionLevel)).finish_non_exhaustive()
}
}
#[cfg(feature = "serialize")]
impl serde::Serialize for TaxRateJurisdictionLevel {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl miniserde::Deserialize for TaxRateJurisdictionLevel {
fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
crate::Place::new(out)
}
}
impl miniserde::de::Visitor for crate::Place<TaxRateJurisdictionLevel> {
fn string(&mut self, s: &str) -> miniserde::Result<()> {
use std::str::FromStr;
self.out = Some(TaxRateJurisdictionLevel::from_str(s).expect("infallible"));
Ok(())
}
}
stripe_types::impl_from_val_with_from_str!(TaxRateJurisdictionLevel);
#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for TaxRateJurisdictionLevel {
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).expect("infallible"))
}
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum TaxRateRateType {
FlatAmount,
Percentage,
Unknown(String),
}
impl TaxRateRateType {
pub fn as_str(&self) -> &str {
use TaxRateRateType::*;
match self {
FlatAmount => "flat_amount",
Percentage => "percentage",
Unknown(v) => v,
}
}
}
impl std::str::FromStr for TaxRateRateType {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use TaxRateRateType::*;
match s {
"flat_amount" => Ok(FlatAmount),
"percentage" => Ok(Percentage),
v => {
tracing::warn!("Unknown value '{}' for enum '{}'", v, "TaxRateRateType");
Ok(Unknown(v.to_owned()))
}
}
}
}
impl std::fmt::Display for TaxRateRateType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(not(feature = "redact-generated-debug"))]
impl std::fmt::Debug for TaxRateRateType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for TaxRateRateType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct(stringify!(TaxRateRateType)).finish_non_exhaustive()
}
}
#[cfg(feature = "serialize")]
impl serde::Serialize for TaxRateRateType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl miniserde::Deserialize for TaxRateRateType {
fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
crate::Place::new(out)
}
}
impl miniserde::de::Visitor for crate::Place<TaxRateRateType> {
fn string(&mut self, s: &str) -> miniserde::Result<()> {
use std::str::FromStr;
self.out = Some(TaxRateRateType::from_str(s).expect("infallible"));
Ok(())
}
}
stripe_types::impl_from_val_with_from_str!(TaxRateRateType);
#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for TaxRateRateType {
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).expect("infallible"))
}
}
impl stripe_types::Object for TaxRate {
type Id = stripe_shared::TaxRateId;
fn id(&self) -> &Self::Id {
&self.id
}
fn into_id(self) -> Self::Id {
self.id
}
}
stripe_types::def_id!(TaxRateId);
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum TaxRateTaxType {
AmusementTax,
CommunicationsTax,
Gst,
Hst,
Igst,
Jct,
LeaseTax,
Pst,
Qst,
RetailDeliveryFee,
Rst,
SalesTax,
ServiceTax,
Vat,
Unknown(String),
}
impl TaxRateTaxType {
pub fn as_str(&self) -> &str {
use TaxRateTaxType::*;
match self {
AmusementTax => "amusement_tax",
CommunicationsTax => "communications_tax",
Gst => "gst",
Hst => "hst",
Igst => "igst",
Jct => "jct",
LeaseTax => "lease_tax",
Pst => "pst",
Qst => "qst",
RetailDeliveryFee => "retail_delivery_fee",
Rst => "rst",
SalesTax => "sales_tax",
ServiceTax => "service_tax",
Vat => "vat",
Unknown(v) => v,
}
}
}
impl std::str::FromStr for TaxRateTaxType {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use TaxRateTaxType::*;
match s {
"amusement_tax" => Ok(AmusementTax),
"communications_tax" => Ok(CommunicationsTax),
"gst" => Ok(Gst),
"hst" => Ok(Hst),
"igst" => Ok(Igst),
"jct" => Ok(Jct),
"lease_tax" => Ok(LeaseTax),
"pst" => Ok(Pst),
"qst" => Ok(Qst),
"retail_delivery_fee" => Ok(RetailDeliveryFee),
"rst" => Ok(Rst),
"sales_tax" => Ok(SalesTax),
"service_tax" => Ok(ServiceTax),
"vat" => Ok(Vat),
v => {
tracing::warn!("Unknown value '{}' for enum '{}'", v, "TaxRateTaxType");
Ok(Unknown(v.to_owned()))
}
}
}
}
impl std::fmt::Display for TaxRateTaxType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(not(feature = "redact-generated-debug"))]
impl std::fmt::Debug for TaxRateTaxType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for TaxRateTaxType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct(stringify!(TaxRateTaxType)).finish_non_exhaustive()
}
}
impl serde::Serialize for TaxRateTaxType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl miniserde::Deserialize for TaxRateTaxType {
fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
crate::Place::new(out)
}
}
impl miniserde::de::Visitor for crate::Place<TaxRateTaxType> {
fn string(&mut self, s: &str) -> miniserde::Result<()> {
use std::str::FromStr;
self.out = Some(TaxRateTaxType::from_str(s).expect("infallible"));
Ok(())
}
}
stripe_types::impl_from_val_with_from_str!(TaxRateTaxType);
#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for TaxRateTaxType {
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).expect("infallible"))
}
}