Skip to main content

ApplePlatform

Enum ApplePlatform 

Source
pub enum ApplePlatform {
Show 13 variants Unknown = 0, MacOS = 1, IOS = 2, TvOS = 3, WatchOS = 4, BridgeOS = 5, MacCatalyst = 6, IOSSimulator = 7, TvOSSimulator = 8, WatchOSSimulator = 9, DriverKit = 10, XrOS = 11, XrOSSimulator = 12,
}
Expand description

Apple platform enumeration.

Matches LLVM’s MachO::PlatformType identifiers. Numeric discriminants are stable and correspond to Mach-O platform IDs, so PartialOrd/Ord order platforms by ID.

Variants§

§

Unknown = 0

§

MacOS = 1

§

IOS = 2

§

TvOS = 3

§

WatchOS = 4

§

BridgeOS = 5

§

MacCatalyst = 6

§

IOSSimulator = 7

§

TvOSSimulator = 8

§

WatchOSSimulator = 9

§

DriverKit = 10

§

XrOS = 11

§

XrOSSimulator = 12

Implementations§

Source§

impl ApplePlatform

Source

pub const ALL: [ApplePlatform; 13]

All platform variants in Mach-O ID order.

Source

pub fn iter() -> impl Iterator<Item = ApplePlatform>

Iterate over all platform variants in Mach-O ID order.

Examples found in repository?
examples/platform.rs (line 11)
3fn main() {
4    println!("=== Apple Platforms (from LLVM MachO.def) ===\n");
5    println!(
6        "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
7        "Platform", "ID", "Target", "TAPI Target", "Marketing", "SDK"
8    );
9    println!("{}", "-".repeat(100));
10
11    for ap in ApplePlatform::iter() {
12        let p = Platform::from(ap);
13        println!(
14            "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
15            p.platform,
16            p.id,
17            p.target,
18            p.tapi_target,
19            p.marketing,
20            p.sdk.unwrap_or("-"),
21        );
22    }
23
24    println!("\nSimulators  (sim → device):");
25    for ap in ApplePlatform::iter().filter(|p| p.is_simulator()) {
26        println!("  {:<22} → {}", ap, ap.device());
27    }
28
29    println!("\nDevice platforms  (device → sim):");
30    for ap in ApplePlatform::iter().filter(|p| p.is_device()) {
31        let sim = ap.simulator()
32            .map(|s| s.to_string())
33            .unwrap_or_else(|| "(none)".to_string());
34        println!("  {:<22} → {}", ap, sim);
35    }
36}
Source

pub fn metadata(self) -> Platform

Returns this platform’s static Platform metadata.

Source

pub fn id(self) -> u32

The Mach-O platform ID.

Source

pub fn from_id(id: u32) -> Option<Self>

Create from a Mach-O platform ID.

Returns None for unrecognised IDs instead of silently falling back to Unknown. Use TryFrom<u32> for the same behaviour as a trait impl.

Source

pub fn from_rust_triple(target: &str) -> Result<Self, ParsePlatformError>

Create from a Rust target triple (e.g. "aarch64-apple-ios-sim").

Returns an error if the triple is not a recognised Apple target.

use apple_platforms::platform::ApplePlatform;
assert_eq!(ApplePlatform::from_rust_triple("aarch64-apple-darwin").unwrap(), ApplePlatform::MacOS);
assert_eq!(ApplePlatform::from_rust_triple("aarch64-apple-ios-sim").unwrap(), ApplePlatform::IOSSimulator);
assert!(ApplePlatform::from_rust_triple("x86_64-unknown-linux-gnu").is_err());
Examples found in repository?
examples/sdk.rs (line 26)
3fn main() {
4    println!("=== Rust Target → SDK Name ===\n");
5
6    let targets = [
7        "aarch64-apple-darwin",
8        "x86_64-apple-darwin",
9        "aarch64-apple-ios",
10        "aarch64-apple-ios-sim",
11        "aarch64-apple-ios-macabi",
12        "aarch64-apple-tvos",
13        "aarch64-apple-tvos-sim",
14        "aarch64-apple-watchos",
15        "aarch64-apple-watchos-sim",
16        "aarch64-apple-visionos",
17        "aarch64-apple-visionos-sim",
18        "aarch64-apple-driverkit",
19        "x86_64-unknown-linux-gnu",   // not Apple — should be None
20    ];
21
22    println!("{:<42}  {:<18}  {}", "Rust triple", "SDK", "Platform");
23    println!("{}", "-".repeat(85));
24    for target in targets {
25        let sdk = triple::to_sdk(target).unwrap_or("(unknown)");
26        let platform = ApplePlatform::from_rust_triple(target)
27            .map(|p| p.to_string())
28            .unwrap_or_else(|_| "(not Apple)".to_string());
29        println!("  {target:<40}  {sdk:<18}  {platform}");
30    }
31}
Source

pub fn sdk(self) -> Option<&'static str>

The SDK name for xcrun --sdk <name>.

Returns None only for the Unknown variant.

Note: MacCatalyst builds use the macOS SDK ("macosx") with the macabi ABI environment.

use apple_platforms::platform::ApplePlatform;
assert_eq!(ApplePlatform::MacOS.sdk(),          Some("macosx"));
assert_eq!(ApplePlatform::IOS.sdk(),            Some("iphoneos"));
assert_eq!(ApplePlatform::IOSSimulator.sdk(),   Some("iphonesimulator"));
assert_eq!(ApplePlatform::MacCatalyst.sdk(),    Some("macosx"));
assert_eq!(ApplePlatform::Unknown.sdk(),        None);
Source

pub fn is_simulator(self) -> bool

Whether this is a simulator platform.

Examples found in repository?
examples/platform.rs (line 25)
3fn main() {
4    println!("=== Apple Platforms (from LLVM MachO.def) ===\n");
5    println!(
6        "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
7        "Platform", "ID", "Target", "TAPI Target", "Marketing", "SDK"
8    );
9    println!("{}", "-".repeat(100));
10
11    for ap in ApplePlatform::iter() {
12        let p = Platform::from(ap);
13        println!(
14            "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
15            p.platform,
16            p.id,
17            p.target,
18            p.tapi_target,
19            p.marketing,
20            p.sdk.unwrap_or("-"),
21        );
22    }
23
24    println!("\nSimulators  (sim → device):");
25    for ap in ApplePlatform::iter().filter(|p| p.is_simulator()) {
26        println!("  {:<22} → {}", ap, ap.device());
27    }
28
29    println!("\nDevice platforms  (device → sim):");
30    for ap in ApplePlatform::iter().filter(|p| p.is_device()) {
31        let sim = ap.simulator()
32            .map(|s| s.to_string())
33            .unwrap_or_else(|| "(none)".to_string());
34        println!("  {:<22} → {}", ap, sim);
35    }
36}
Source

pub fn is_device(self) -> bool

Whether this is a real-device platform (non-simulator, non-Unknown).

Examples found in repository?
examples/platform.rs (line 30)
3fn main() {
4    println!("=== Apple Platforms (from LLVM MachO.def) ===\n");
5    println!(
6        "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
7        "Platform", "ID", "Target", "TAPI Target", "Marketing", "SDK"
8    );
9    println!("{}", "-".repeat(100));
10
11    for ap in ApplePlatform::iter() {
12        let p = Platform::from(ap);
13        println!(
14            "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
15            p.platform,
16            p.id,
17            p.target,
18            p.tapi_target,
19            p.marketing,
20            p.sdk.unwrap_or("-"),
21        );
22    }
23
24    println!("\nSimulators  (sim → device):");
25    for ap in ApplePlatform::iter().filter(|p| p.is_simulator()) {
26        println!("  {:<22} → {}", ap, ap.device());
27    }
28
29    println!("\nDevice platforms  (device → sim):");
30    for ap in ApplePlatform::iter().filter(|p| p.is_device()) {
31        let sim = ap.simulator()
32            .map(|s| s.to_string())
33            .unwrap_or_else(|| "(none)".to_string());
34        println!("  {:<22} → {}", ap, sim);
35    }
36}
Source

pub fn device(self) -> Self

The corresponding device (non-simulator) platform.

Returns self if already a device platform.

use apple_platforms::platform::ApplePlatform;
assert_eq!(ApplePlatform::IOSSimulator.device(), ApplePlatform::IOS);
assert_eq!(ApplePlatform::IOS.device(),          ApplePlatform::IOS);
Examples found in repository?
examples/platform.rs (line 26)
3fn main() {
4    println!("=== Apple Platforms (from LLVM MachO.def) ===\n");
5    println!(
6        "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
7        "Platform", "ID", "Target", "TAPI Target", "Marketing", "SDK"
8    );
9    println!("{}", "-".repeat(100));
10
11    for ap in ApplePlatform::iter() {
12        let p = Platform::from(ap);
13        println!(
14            "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
15            p.platform,
16            p.id,
17            p.target,
18            p.tapi_target,
19            p.marketing,
20            p.sdk.unwrap_or("-"),
21        );
22    }
23
24    println!("\nSimulators  (sim → device):");
25    for ap in ApplePlatform::iter().filter(|p| p.is_simulator()) {
26        println!("  {:<22} → {}", ap, ap.device());
27    }
28
29    println!("\nDevice platforms  (device → sim):");
30    for ap in ApplePlatform::iter().filter(|p| p.is_device()) {
31        let sim = ap.simulator()
32            .map(|s| s.to_string())
33            .unwrap_or_else(|| "(none)".to_string());
34        println!("  {:<22} → {}", ap, sim);
35    }
36}
Source

pub fn simulator(self) -> Option<Self>

The corresponding simulator platform, or None if this platform has no simulator counterpart (e.g. macOS, DriverKit, BridgeOS).

Returns Some(self) if already a simulator.

use apple_platforms::platform::ApplePlatform;
assert_eq!(ApplePlatform::IOS.simulator(),            Some(ApplePlatform::IOSSimulator));
assert_eq!(ApplePlatform::IOSSimulator.simulator(),   Some(ApplePlatform::IOSSimulator));
assert_eq!(ApplePlatform::MacOS.simulator(),          None);
assert_eq!(ApplePlatform::DriverKit.simulator(),      None);
Examples found in repository?
examples/platform.rs (line 31)
3fn main() {
4    println!("=== Apple Platforms (from LLVM MachO.def) ===\n");
5    println!(
6        "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
7        "Platform", "ID", "Target", "TAPI Target", "Marketing", "SDK"
8    );
9    println!("{}", "-".repeat(100));
10
11    for ap in ApplePlatform::iter() {
12        let p = Platform::from(ap);
13        println!(
14            "{:<20} {:>2}  {:<18} {:<18} {:<22} {}",
15            p.platform,
16            p.id,
17            p.target,
18            p.tapi_target,
19            p.marketing,
20            p.sdk.unwrap_or("-"),
21        );
22    }
23
24    println!("\nSimulators  (sim → device):");
25    for ap in ApplePlatform::iter().filter(|p| p.is_simulator()) {
26        println!("  {:<22} → {}", ap, ap.device());
27    }
28
29    println!("\nDevice platforms  (device → sim):");
30    for ap in ApplePlatform::iter().filter(|p| p.is_device()) {
31        let sim = ap.simulator()
32            .map(|s| s.to_string())
33            .unwrap_or_else(|| "(none)".to_string());
34        println!("  {:<22} → {}", ap, sim);
35    }
36}

Trait Implementations§

Source§

impl Clone for ApplePlatform

Source§

fn clone(&self) -> ApplePlatform

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ApplePlatform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ApplePlatform

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for ApplePlatform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ApplePlatform> for Platform

Source§

fn from(value: ApplePlatform) -> Self

Converts to this type from the input type.
Source§

impl FromStr for ApplePlatform

Source§

type Err = ParsePlatformError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for ApplePlatform

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for ApplePlatform

Source§

fn cmp(&self, other: &ApplePlatform) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ApplePlatform

Source§

fn eq(&self, other: &ApplePlatform) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for ApplePlatform

Source§

fn partial_cmp(&self, other: &ApplePlatform) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<Platform> for ApplePlatform

Convert a Platform back to an ApplePlatform by its numeric ID.

Fails if p.id does not correspond to a known platform.

Source§

type Error = ParsePlatformError

The type returned in the event of a conversion error.
Source§

fn try_from(p: Platform) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u32> for ApplePlatform

Source§

type Error = ParsePlatformError

The type returned in the event of a conversion error.
Source§

fn try_from(id: u32) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<usize> for ApplePlatform

Source§

type Error = ParsePlatformError

The type returned in the event of a conversion error.
Source§

fn try_from(id: usize) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for ApplePlatform

Source§

impl Eq for ApplePlatform

Source§

impl StructuralPartialEq for ApplePlatform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.