2020-03-31 15:22:00 -07:00
|
|
|
//! This module contains some lightweight wrappers over Foundation data types.
|
|
|
|
//!
|
|
|
|
//! Some of it is pulled/inspired from Servo's cocoa-rs (e.g, the "id" type). While
|
2020-03-17 16:55:09 -07:00
|
|
|
//! this isn't a clone of their module (we don't need everything from there, but remaining
|
|
|
|
//! compatible in case an end-user wants to drop that low is deal), it's worth linking their
|
|
|
|
//! license and repository - they've done really incredible work and it's 100% worth acknowledging.
|
|
|
|
//!
|
|
|
|
//! - [core-foundation-rs Repository](https://github.com/servo/core-foundation-rs)
|
|
|
|
//! - [core-foundation-rs MIT License](https://github.com/servo/core-foundation-rs/blob/master/LICENSE-MIT)
|
|
|
|
//! - [core-foundation-rs Apache License](https://github.com/servo/core-foundation-rs/blob/master/LICENSE-APACHE)
|
2020-03-31 15:22:00 -07:00
|
|
|
//!
|
|
|
|
//! ## Why?
|
|
|
|
//! A good question. The existing wrappers tend to use traits over `id`, which works well for some
|
|
|
|
//! cases, but I found it frustrating and messy trying to work with them. These provide the API I
|
|
|
|
//! was looking for, and help provide all the proper `retain`/`release` logic needed for the
|
|
|
|
//! Objective-C side.
|
2020-03-17 16:55:09 -07:00
|
|
|
|
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
#![allow(non_upper_case_globals)]
|
|
|
|
|
|
|
|
use objc::runtime;
|
|
|
|
pub use objc::runtime::{BOOL, NO, YES};
|
|
|
|
|
2020-03-31 15:22:00 -07:00
|
|
|
mod autoreleasepool;
|
2020-03-17 16:55:09 -07:00
|
|
|
pub use autoreleasepool::AutoReleasePool;
|
|
|
|
|
2020-03-31 15:22:00 -07:00
|
|
|
mod array;
|
2020-03-17 16:55:09 -07:00
|
|
|
pub use array::NSArray;
|
|
|
|
|
2021-02-07 20:25:56 -08:00
|
|
|
mod class;
|
|
|
|
pub use class::load_or_register_class;
|
|
|
|
|
2020-03-31 15:22:00 -07:00
|
|
|
mod data;
|
|
|
|
pub use data::NSData;
|
2020-03-17 16:55:09 -07:00
|
|
|
|
2020-03-31 15:22:00 -07:00
|
|
|
mod dictionary;
|
2021-03-04 17:24:39 -08:00
|
|
|
pub use dictionary::NSMutableDictionary;
|
2020-03-17 16:55:09 -07:00
|
|
|
|
2020-03-31 15:22:00 -07:00
|
|
|
mod number;
|
|
|
|
pub use number::NSNumber;
|
|
|
|
|
|
|
|
mod string;
|
|
|
|
pub use string::NSString;
|
|
|
|
|
2022-01-02 02:35:12 -08:00
|
|
|
// Separate named module to not conflict with the `url` crate. Go figure.
|
|
|
|
mod urls;
|
|
|
|
pub use urls::{NSURL, NSURLBookmarkCreationOption, NSURLBookmarkResolutionOption};
|
|
|
|
|
2021-02-08 11:54:35 -08:00
|
|
|
/// Bool mapping types differ between ARM and x64. There's a number of places that we need to check
|
|
|
|
/// against BOOL results throughout the framework, and this just simplifies some mismatches.
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn to_bool(result: BOOL) -> bool {
|
|
|
|
match result {
|
|
|
|
YES => true,
|
|
|
|
NO => false,
|
|
|
|
|
|
|
|
//#[cfg(target_arch = "aarch64")]
|
|
|
|
#[cfg(not(target_arch = "aarch64"))]
|
|
|
|
_ => { std::unreachable!(); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 15:22:00 -07:00
|
|
|
/// More or less maps over to Objective-C's `id` type, which... can really be anything.
|
2020-03-17 16:55:09 -07:00
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub type id = *mut runtime::Object;
|
|
|
|
|
2020-03-31 15:22:00 -07:00
|
|
|
/// Exactly what it sounds like.
|
2020-03-17 16:55:09 -07:00
|
|
|
#[allow(non_upper_case_globals)]
|
|
|
|
pub const nil: id = 0 as id;
|
|
|
|
|
2020-03-31 15:22:00 -07:00
|
|
|
/// Platform-specific.
|
2020-03-17 16:55:09 -07:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
pub type NSInteger = libc::c_int;
|
2020-03-31 15:22:00 -07:00
|
|
|
|
|
|
|
/// Platform-specific.
|
2020-03-17 16:55:09 -07:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
pub type NSUInteger = libc::c_uint;
|
|
|
|
|
2020-03-31 15:22:00 -07:00
|
|
|
/// Platform-specific.
|
2020-03-17 16:55:09 -07:00
|
|
|
#[cfg(target_pointer_width = "64")]
|
|
|
|
pub type NSInteger = libc::c_long;
|
2020-03-31 15:22:00 -07:00
|
|
|
|
|
|
|
/// Platform-specific.
|
2020-03-17 16:55:09 -07:00
|
|
|
#[cfg(target_pointer_width = "64")]
|
|
|
|
pub type NSUInteger = libc::c_ulong;
|