async-stripe-shared 1.0.0-rc.6

API bindings for the Stripe HTTP API
Documentation
/// A test clock enables deterministic control over objects in testmode.
/// With a test clock, you can create.
/// objects at a frozen time in the past or future, and advance to a specific future time to observe webhooks and state changes.
/// After the clock advances,.
/// you can either validate the current state of your scenario (and test your assumptions), change the current state of your scenario (and test more complex scenarios), or keep advancing forward in time.
#[derive(Clone, Eq, PartialEq)]
#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct TestHelpersTestClock {
    /// Time at which the object was created. Measured in seconds since the Unix epoch.
    pub created: stripe_types::Timestamp,
    /// Time at which this clock is scheduled to auto delete.
    pub deletes_after: stripe_types::Timestamp,
    /// Time at which all objects belonging to this clock are frozen.
    pub frozen_time: stripe_types::Timestamp,
    /// Unique identifier for the object.
    pub id: stripe_shared::TestHelpersTestClockId,
    /// If the object exists in live mode, the value is `true`.
    /// If the object exists in test mode, the value is `false`.
    pub livemode: bool,
    /// The custom name supplied at creation.
    pub name: Option<String>,
    /// The status of the Test Clock.
    pub status: TestHelpersTestClockStatus,
    pub status_details: stripe_shared::BillingClocksResourceStatusDetailsStatusDetails,
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for TestHelpersTestClock {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.debug_struct("TestHelpersTestClock").finish_non_exhaustive()
    }
}
#[doc(hidden)]
pub struct TestHelpersTestClockBuilder {
    created: Option<stripe_types::Timestamp>,
    deletes_after: Option<stripe_types::Timestamp>,
    frozen_time: Option<stripe_types::Timestamp>,
    id: Option<stripe_shared::TestHelpersTestClockId>,
    livemode: Option<bool>,
    name: Option<Option<String>>,
    status: Option<TestHelpersTestClockStatus>,
    status_details: Option<stripe_shared::BillingClocksResourceStatusDetailsStatusDetails>,
}

#[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 TestHelpersTestClock {
        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
            Place::new(out)
        }
    }

    struct Builder<'a> {
        out: &'a mut Option<TestHelpersTestClock>,
        builder: TestHelpersTestClockBuilder,
    }

    impl Visitor for Place<TestHelpersTestClock> {
        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
            Ok(Box::new(Builder {
                out: &mut self.out,
                builder: TestHelpersTestClockBuilder::deser_default(),
            }))
        }
    }

    impl MapBuilder for TestHelpersTestClockBuilder {
        type Out = TestHelpersTestClock;
        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
            Ok(match k {
                "created" => Deserialize::begin(&mut self.created),
                "deletes_after" => Deserialize::begin(&mut self.deletes_after),
                "frozen_time" => Deserialize::begin(&mut self.frozen_time),
                "id" => Deserialize::begin(&mut self.id),
                "livemode" => Deserialize::begin(&mut self.livemode),
                "name" => Deserialize::begin(&mut self.name),
                "status" => Deserialize::begin(&mut self.status),
                "status_details" => Deserialize::begin(&mut self.status_details),
                _ => <dyn Visitor>::ignore(),
            })
        }

        fn deser_default() -> Self {
            Self {
                created: None,
                deletes_after: None,
                frozen_time: None,
                id: None,
                livemode: None,
                name: Some(None),
                status: None,
                status_details: None,
            }
        }

        fn take_out(&mut self) -> Option<Self::Out> {
            let (
                Some(created),
                Some(deletes_after),
                Some(frozen_time),
                Some(id),
                Some(livemode),
                Some(name),
                Some(status),
                Some(status_details),
            ) = (
                self.created,
                self.deletes_after,
                self.frozen_time,
                self.id.take(),
                self.livemode,
                self.name.take(),
                self.status.take(),
                self.status_details,
            )
            else {
                return None;
            };
            Some(Self::Out {
                created,
                deletes_after,
                frozen_time,
                id,
                livemode,
                name,
                status,
                status_details,
            })
        }
    }

    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 TestHelpersTestClock {
        type Builder = TestHelpersTestClockBuilder;
    }

    impl FromValueOpt for TestHelpersTestClock {
        fn from_value(v: Value) -> Option<Self> {
            let Value::Object(obj) = v else {
                return None;
            };
            let mut b = TestHelpersTestClockBuilder::deser_default();
            for (k, v) in obj {
                match k.as_str() {
                    "created" => b.created = FromValueOpt::from_value(v),
                    "deletes_after" => b.deletes_after = FromValueOpt::from_value(v),
                    "frozen_time" => b.frozen_time = FromValueOpt::from_value(v),
                    "id" => b.id = FromValueOpt::from_value(v),
                    "livemode" => b.livemode = FromValueOpt::from_value(v),
                    "name" => b.name = FromValueOpt::from_value(v),
                    "status" => b.status = FromValueOpt::from_value(v),
                    "status_details" => b.status_details = FromValueOpt::from_value(v),
                    _ => {}
                }
            }
            b.take_out()
        }
    }
};
#[cfg(feature = "serialize")]
impl serde::Serialize for TestHelpersTestClock {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        use serde::ser::SerializeStruct;
        let mut s = s.serialize_struct("TestHelpersTestClock", 9)?;
        s.serialize_field("created", &self.created)?;
        s.serialize_field("deletes_after", &self.deletes_after)?;
        s.serialize_field("frozen_time", &self.frozen_time)?;
        s.serialize_field("id", &self.id)?;
        s.serialize_field("livemode", &self.livemode)?;
        s.serialize_field("name", &self.name)?;
        s.serialize_field("status", &self.status)?;
        s.serialize_field("status_details", &self.status_details)?;

        s.serialize_field("object", "test_helpers.test_clock")?;
        s.end()
    }
}
/// The status of the Test Clock.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum TestHelpersTestClockStatus {
    Advancing,
    InternalFailure,
    Ready,
    /// An unrecognized value from Stripe. Should not be used as a request parameter.
    Unknown(String),
}
impl TestHelpersTestClockStatus {
    pub fn as_str(&self) -> &str {
        use TestHelpersTestClockStatus::*;
        match self {
            Advancing => "advancing",
            InternalFailure => "internal_failure",
            Ready => "ready",
            Unknown(v) => v,
        }
    }
}

impl std::str::FromStr for TestHelpersTestClockStatus {
    type Err = std::convert::Infallible;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        use TestHelpersTestClockStatus::*;
        match s {
            "advancing" => Ok(Advancing),
            "internal_failure" => Ok(InternalFailure),
            "ready" => Ok(Ready),
            v => {
                tracing::warn!("Unknown value '{}' for enum '{}'", v, "TestHelpersTestClockStatus");
                Ok(Unknown(v.to_owned()))
            }
        }
    }
}
impl std::fmt::Display for TestHelpersTestClockStatus {
    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 TestHelpersTestClockStatus {
    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 TestHelpersTestClockStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.debug_struct(stringify!(TestHelpersTestClockStatus)).finish_non_exhaustive()
    }
}
#[cfg(feature = "serialize")]
impl serde::Serialize for TestHelpersTestClockStatus {
    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 TestHelpersTestClockStatus {
    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
        crate::Place::new(out)
    }
}

impl miniserde::de::Visitor for crate::Place<TestHelpersTestClockStatus> {
    fn string(&mut self, s: &str) -> miniserde::Result<()> {
        use std::str::FromStr;
        self.out = Some(TestHelpersTestClockStatus::from_str(s).expect("infallible"));
        Ok(())
    }
}

stripe_types::impl_from_val_with_from_str!(TestHelpersTestClockStatus);
#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for TestHelpersTestClockStatus {
    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 TestHelpersTestClock {
    type Id = stripe_shared::TestHelpersTestClockId;
    fn id(&self) -> &Self::Id {
        &self.id
    }

    fn into_id(self) -> Self::Id {
        self.id
    }
}
stripe_types::def_id!(TestHelpersTestClockId);