Skip to main content

storekit/
message.rs

1use crate::error::StoreKitError;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4/// Wraps `StoreKit.Message.Reason`.
5pub enum MessageReason {
6    /// Represents the `Generic` `StoreKit` case.
7    Generic,
8    /// Represents the `PriceIncreaseConsent` `StoreKit` case.
9    PriceIncreaseConsent,
10    /// Represents the `BillingIssue` `StoreKit` case.
11    BillingIssue,
12    /// Represents the `WinBackOffer` `StoreKit` case.
13    WinBackOffer,
14    /// Preserves an unrecognized `StoreKit` case.
15    Unknown(i64),
16}
17
18#[derive(Debug, Clone, PartialEq, Eq)]
19/// Wraps `StoreKit.Message`.
20pub struct Message {
21    /// Reason reported by `StoreKit`.
22    pub reason: MessageReason,
23    /// Localized reason reported by `StoreKit`.
24    pub localized_reason: Option<String>,
25}
26
27#[derive(Debug, Clone, Copy, Default)]
28/// Represents the `StoreKit` message stream.
29pub struct MessageStream;
30
31impl Message {
32    /// Returns whether `StoreKit.Message` is available on this platform.
33    pub const fn is_supported() -> bool {
34        false
35    }
36
37    /// Returns the `StoreKit` message stream when the API is available on this platform.
38    pub fn messages() -> Result<MessageStream, StoreKitError> {
39        Err(StoreKitError::NotSupported(
40            "StoreKit.Message is unavailable on macOS".to_owned(),
41        ))
42    }
43}
44
45impl MessageStream {
46    #[allow(clippy::should_implement_trait)]
47    /// Waits for the next value from the `StoreKit` stream using the default timeout.
48    pub fn next(&mut self) -> Result<Option<Message>, StoreKitError> {
49        Err(StoreKitError::NotSupported(
50            "StoreKit.Message is unavailable on macOS".to_owned(),
51        ))
52    }
53}