Skip to main content

app_store_server_library/models/
platform.rs

1use serde::{Deserialize, Serialize};
2
3/// The platform on which the customer consumed the in-app purchase.
4///
5/// [platform](https://developer.apple.com/documentation/appstoreserverapi/platform)
6#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq)]
7#[serde(from = "i64", into = "i64")]
8pub enum Platform {
9    Undeclared,
10    Apple,
11    NonApple,
12
13    /// A value the App Store sent that this version of the
14    /// library does not support, preserved as received.
15    NotSupported(i64),
16}
17
18impl From<i64> for Platform {
19    fn from(value: i64) -> Self {
20        match value {
21            0 => Platform::Undeclared,
22            1 => Platform::Apple,
23            2 => Platform::NonApple,
24            other => Platform::NotSupported(other),
25        }
26    }
27}
28
29impl From<Platform> for i64 {
30    fn from(value: Platform) -> Self {
31        match value {
32            Platform::Undeclared => 0,
33            Platform::Apple => 1,
34            Platform::NonApple => 2,
35            Platform::NotSupported(other) => other,
36        }
37    }
38}