Skip to main content

mtl_foundation/
lib.rs

1// Clippy allows for legacy API patterns
2#![allow(clippy::self_named_constructors)]
3#![allow(clippy::not_unsafe_ptr_arg_deref)]
4#![allow(clippy::should_implement_trait)]
5#![allow(clippy::new_without_default)]
6
7//! Foundation framework bindings for Rust.
8//!
9//! This crate provides Rust bindings to Apple's Foundation framework,
10//! corresponding to the C++ headers in `metal-cpp/Foundation/`.
11//!
12//! # Overview
13//!
14//! The Foundation framework provides fundamental classes for Objective-C
15//! programming, including:
16//!
17//! - Basic types: [`Integer`], [`UInteger`], [`TimeInterval`]
18//! - Objects: [`Object`], [`String`], [`Array`], [`Dictionary`], [`Data`]
19//! - Numbers: [`Number`], [`Value`]
20//! - Error handling: [`Error`]
21//! - URL handling: [`Url`]
22//! - Memory management: [`SharedPtr`], [`AutoreleasePool`]
23//! - System info: [`ProcessInfo`], [`Bundle`]
24//!
25//! # C++ Correspondence
26//!
27//! This crate provides 1:1 correspondence with the metal-cpp Foundation headers:
28//!
29//! | C++ Header | Rust Module |
30//! |------------|-------------|
31//! | `NSTypes.hpp` | [`types`] |
32//! | `NSObjCRuntime.hpp` | [`objc_runtime`] |
33//! | `NSRange.hpp` | [`range`] |
34//! | `NSObject.hpp` | [`object`] |
35//! | `NSSharedPtr.hpp` | [`shared_ptr`] |
36//! | `NSString.hpp` | [`string`] |
37//! | `NSArray.hpp` | [`array`] |
38//! | `NSDictionary.hpp` | [`dictionary`] |
39//! | `NSSet.hpp` | [`set`] |
40//! | `NSData.hpp` | [`data`] |
41//! | `NSNumber.hpp` | [`number`] |
42//! | `NSDate.hpp` | [`date`] |
43//! | `NSError.hpp` | [`error`] |
44//! | `NSURL.hpp` | [`url`] |
45//! | `NSEnumerator.hpp` | [`enumerator`] |
46//! | `NSAutoreleasePool.hpp` | [`autorelease`] |
47//! | `NSNotification.hpp` | [`notification`] |
48//! | `NSLock.hpp` | [`lock`] |
49//! | `NSBundle.hpp` | [`bundle`] |
50//! | `NSProcessInfo.hpp` | [`process_info`] |
51
52// Modules
53pub mod array;
54pub mod autorelease;
55pub mod bundle;
56pub mod data;
57pub mod date;
58pub mod dictionary;
59pub mod enumerator;
60pub mod error;
61pub mod lock;
62pub mod notification;
63pub mod number;
64pub mod objc_runtime;
65pub mod object;
66pub mod process_info;
67pub mod range;
68pub mod set;
69pub mod shared_ptr;
70pub mod string;
71pub mod types;
72pub mod url;
73
74// Re-export commonly used types at crate root
75
76// Types
77pub use types::{INTEGER_MAX, INTEGER_MIN, UINTEGER_MAX};
78pub use types::{Integer, OperatingSystemVersion, TimeInterval, UInteger};
79
80// ObjC Runtime
81pub use objc_runtime::{ComparisonResult, NOT_FOUND};
82
83// Range
84pub use range::Range;
85
86// Object traits
87pub use object::{Copying, Object, Referencing, SecureCoding};
88
89// SharedPtr
90pub use shared_ptr::{SharedPtr, retain_ptr, transfer_ptr};
91
92// String
93pub use string::{String, StringCompareOptions, StringEncoding, Unichar};
94
95// Array
96pub use array::Array;
97
98// Dictionary
99pub use dictionary::Dictionary;
100
101// Set
102pub use set::Set;
103
104// Data
105pub use data::Data;
106
107// Number
108pub use number::{Number, Value};
109
110// Date
111pub use date::Date;
112
113// Error
114pub use error::{Error, ErrorDomain, ErrorUserInfoKey};
115pub use error::{
116    cocoa_error_domain, debug_description_error_key, file_path_error_key, help_anchor_error_key,
117    localized_description_key, localized_failure_error_key, localized_failure_reason_error_key,
118    localized_recovery_options_error_key, localized_recovery_suggestion_error_key,
119    mach_error_domain, os_status_error_domain, posix_error_domain, recovery_attempter_error_key,
120    string_encoding_error_key, underlying_error_key, url_error_key,
121};
122
123// Enumerator
124pub use enumerator::{Enumerator, FastEnumeration, FastEnumerationState};
125
126// URL
127pub use url::Url;
128
129// Autorelease
130pub use autorelease::{AutoreleasePool, AutoreleasePoolScope};
131
132// Notification
133pub use notification::{Notification, NotificationCenter, NotificationName};
134
135// Lock
136pub use lock::{Condition, Locking};
137
138// Bundle
139pub use bundle::Bundle;
140pub use bundle::{
141    localized_string, localized_string_from_table, localized_string_from_table_in_bundle,
142    localized_string_with_default_value,
143};
144
145// ProcessInfo
146pub use process_info::{
147    ActivityOptions, DeviceCertification, ProcessInfo, ProcessInfoThermalState,
148    ProcessPerformanceProfile,
149};
150
151#[cfg(test)]
152mod tests {
153    use super::*;
154
155    #[test]
156    fn test_module_imports() {
157        // Verify that all re-exports compile
158        let _: Integer = 0;
159        let _: UInteger = 0;
160        let _ = ComparisonResult::ORDERED_SAME;
161        let _ = Range::new(0, 10);
162    }
163}