objc_sys/
constants.rs

1//! Various common #defines and enum constants.
2
3#[cfg(any(doc, target_vendor = "apple"))]
4use std::os::raw::c_int;
5
6use crate::{id, objc_class, BOOL};
7
8/// The equivalent of `true` for Objective-C's [`BOOL`][`super::BOOL`] type.
9#[allow(clippy::unnecessary_cast)]
10pub const YES: BOOL = true as BOOL; // true -> 1
11
12/// The equivalent of `false` for Objective-C's [`BOOL`][`super::BOOL`] type.
13#[allow(clippy::unnecessary_cast)]
14pub const NO: BOOL = false as BOOL; // false -> 0
15
16/// A quick alias for a [`null_mut`][`core::ptr::null_mut`] object / instance.
17pub const nil: id = 0 as *mut _;
18
19/// A quick alias for a [`null_mut`][`core::ptr::null_mut`] class.
20pub const Nil: *mut objc_class = 0 as *mut _;
21
22/// Policies related to associative references.
23///
24/// These are options to [`objc_setAssociatedObject`].
25///
26/// [`objc_setAssociatedObject`]: crate::objc_setAssociatedObject
27pub type objc_AssociationPolicy = usize;
28/// Specifies a weak reference to the associated object.
29///
30/// This performs straight assignment, without message sends.
31pub const OBJC_ASSOCIATION_ASSIGN: objc_AssociationPolicy = 0;
32/// Specifies a strong reference to the associated object.
33///
34/// The association is not made atomically.
35pub const OBJC_ASSOCIATION_RETAIN_NONATOMIC: objc_AssociationPolicy = 1;
36/// Specifies that the associated object is copied.
37///
38/// The association is not made atomically.
39pub const OBJC_ASSOCIATION_COPY_NONATOMIC: objc_AssociationPolicy = 3;
40/// Specifies a strong reference to the associated object.
41///
42/// The association is made atomically.
43pub const OBJC_ASSOCIATION_RETAIN: objc_AssociationPolicy = 0o1401;
44/// Specifies that the associated object is copied.
45///
46/// The association is made atomically.
47pub const OBJC_ASSOCIATION_COPY: objc_AssociationPolicy = 0o1403;
48
49#[cfg(any(doc, target_vendor = "apple"))]
50pub const OBJC_SYNC_SUCCESS: c_int = 0;
51#[cfg(any(doc, target_vendor = "apple"))]
52pub const OBJC_SYNC_NOT_OWNING_THREAD_ERROR: c_int = -1;
53/// Only relevant before macOS 10.13
54#[cfg(any(doc, target_vendor = "apple"))]
55pub const OBJC_SYNC_TIMED_OUT: c_int = -2;
56/// Only relevant before macOS 10.13
57#[cfg(any(doc, target_vendor = "apple"))]
58pub const OBJC_SYNC_NOT_INITIALIZED: c_int = -3;
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63    #[test]
64    fn test_association_policy() {
65        assert_eq!(OBJC_ASSOCIATION_RETAIN, 769);
66        assert_eq!(OBJC_ASSOCIATION_COPY, 771);
67
68        // What the GNUStep headers define
69        assert_eq!(OBJC_ASSOCIATION_RETAIN, 0x301);
70        assert_eq!(OBJC_ASSOCIATION_COPY, 0x303);
71    }
72}