1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#[derive(Debug, Clone, PartialEq, Eq)]
/// Wraps `StoreKit.Product.SubscriptionInfo.RenewalState`.
pub enum RenewalState {
/// Represents the `Subscribed` `StoreKit` case.
Subscribed,
/// Represents the `Expired` `StoreKit` case.
Expired,
/// Represents the `InBillingRetryPeriod` `StoreKit` case.
InBillingRetryPeriod,
/// Represents the `InGracePeriod` `StoreKit` case.
InGracePeriod,
/// Represents the `Revoked` `StoreKit` case.
Revoked,
/// Preserves an unrecognized `StoreKit` case.
Unknown(String),
}
impl RenewalState {
/// Returns the raw `StoreKit` string for this renewal state.
pub fn as_str(&self) -> &str {
match self {
Self::Subscribed => "subscribed",
Self::Expired => "expired",
Self::InBillingRetryPeriod => "inBillingRetryPeriod",
Self::InGracePeriod => "inGracePeriod",
Self::Revoked => "revoked",
Self::Unknown(value) => value.as_str(),
}
}
/// Builds a renewal state from the raw `StoreKit` string.
pub fn from_raw(raw: impl Into<String>) -> Self {
match raw.into().as_str() {
"subscribed" => Self::Subscribed,
"expired" => Self::Expired,
"inBillingRetryPeriod" => Self::InBillingRetryPeriod,
"inGracePeriod" => Self::InGracePeriod,
"revoked" => Self::Revoked,
other => Self::Unknown(other.to_owned()),
}
}
}