objc2_foundation/generated/
NSObject.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9extern_protocol!(
10    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nscoding?language=objc)
11    pub unsafe trait NSCoding {
12        #[cfg(feature = "NSCoder")]
13        /// # Safety
14        ///
15        /// `coder` possibly has further requirements.
16        #[unsafe(method(encodeWithCoder:))]
17        #[unsafe(method_family = none)]
18        unsafe fn encodeWithCoder(&self, coder: &NSCoder);
19
20        #[cfg(feature = "NSCoder")]
21        /// # Safety
22        ///
23        /// `coder` possibly has further requirements.
24        #[unsafe(method(initWithCoder:))]
25        #[unsafe(method_family = init)]
26        unsafe fn initWithCoder(this: Allocated<Self>, coder: &NSCoder) -> Option<Retained<Self>>;
27    }
28);
29
30extern_protocol!(
31    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nssecurecoding?language=objc)
32    pub unsafe trait NSSecureCoding: NSCoding {
33        #[unsafe(method(supportsSecureCoding))]
34        #[unsafe(method_family = none)]
35        fn supportsSecureCoding() -> bool;
36    }
37);
38
39mod private_NSObjectNSCoderMethods {
40    pub trait Sealed {}
41}
42
43/// Category "NSCoderMethods" on [`NSObject`].
44///
45/// *********    Base class        **********
46#[doc(alias = "NSCoderMethods")]
47pub unsafe trait NSObjectNSCoderMethods:
48    ClassType + Sized + private_NSObjectNSCoderMethods::Sealed
49{
50    extern_methods!(
51        #[unsafe(method(version))]
52        #[unsafe(method_family = none)]
53        fn version() -> NSInteger;
54
55        #[unsafe(method(setVersion:))]
56        #[unsafe(method_family = none)]
57        unsafe fn setVersion(a_version: NSInteger);
58
59        #[unsafe(method(classForCoder))]
60        #[unsafe(method_family = none)]
61        fn classForCoder(&self) -> &'static AnyClass;
62
63        #[cfg(feature = "NSCoder")]
64        /// # Safety
65        ///
66        /// `coder` possibly has further requirements.
67        #[unsafe(method(replacementObjectForCoder:))]
68        #[unsafe(method_family = none)]
69        unsafe fn replacementObjectForCoder(&self, coder: &NSCoder) -> Option<Retained<AnyObject>>;
70    );
71}
72
73impl private_NSObjectNSCoderMethods::Sealed for NSObject {}
74unsafe impl NSObjectNSCoderMethods for NSObject {}
75
76extern_protocol!(
77    /// *********    Discardable Content        **********
78    ///
79    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdiscardablecontent?language=objc)
80    pub unsafe trait NSDiscardableContent {
81        #[unsafe(method(beginContentAccess))]
82        #[unsafe(method_family = none)]
83        fn beginContentAccess(&self) -> bool;
84
85        #[unsafe(method(endContentAccess))]
86        #[unsafe(method_family = none)]
87        fn endContentAccess(&self);
88
89        #[unsafe(method(discardContentIfPossible))]
90        #[unsafe(method_family = none)]
91        fn discardContentIfPossible(&self);
92
93        #[unsafe(method(isContentDiscarded))]
94        #[unsafe(method_family = none)]
95        fn isContentDiscarded(&self) -> bool;
96    }
97);
98
99mod private_NSObjectNSDiscardableContentProxy {
100    pub trait Sealed {}
101}
102
103/// Category "NSDiscardableContentProxy" on [`NSObject`].
104#[doc(alias = "NSDiscardableContentProxy")]
105pub unsafe trait NSObjectNSDiscardableContentProxy:
106    ClassType + Sized + private_NSObjectNSDiscardableContentProxy::Sealed
107{
108    extern_methods!(
109        #[unsafe(method(autoContentAccessingProxy))]
110        #[unsafe(method_family = none)]
111        fn autoContentAccessingProxy(&self) -> Retained<AnyObject>;
112    );
113}
114
115impl private_NSObjectNSDiscardableContentProxy::Sealed for NSObject {}
116unsafe impl NSObjectNSDiscardableContentProxy for NSObject {}
117
118/// *********    Object Allocation / Deallocation        ******
119///
120/// # Safety
121///
122/// - `a_class` probably has further requirements.
123/// - `zone` must be a valid pointer or null.
124#[cfg(feature = "NSZone")]
125#[inline]
126pub unsafe extern "C-unwind" fn NSAllocateObject(
127    a_class: &AnyClass,
128    extra_bytes: NSUInteger,
129    zone: *mut NSZone,
130) -> Retained<AnyObject> {
131    extern "C-unwind" {
132        fn NSAllocateObject(
133            a_class: &AnyClass,
134            extra_bytes: NSUInteger,
135            zone: *mut NSZone,
136        ) -> *mut AnyObject;
137    }
138    let ret = unsafe { NSAllocateObject(a_class, extra_bytes, zone) };
139    unsafe { Retained::retain_autoreleased(ret) }
140        .expect("function was marked as returning non-null, but actually returned NULL")
141}
142
143extern "C-unwind" {
144    /// # Safety
145    ///
146    /// `object` should be of the correct type.
147    pub fn NSDeallocateObject(object: &AnyObject);
148}
149
150/// # Safety
151///
152/// - `object` should be of the correct type.
153/// - `zone` must be a valid pointer or null.
154#[cfg(feature = "NSZone")]
155#[deprecated = "Not supported"]
156#[inline]
157pub unsafe extern "C-unwind" fn NSCopyObject(
158    object: &AnyObject,
159    extra_bytes: NSUInteger,
160    zone: *mut NSZone,
161) -> Retained<AnyObject> {
162    extern "C-unwind" {
163        fn NSCopyObject(
164            object: &AnyObject,
165            extra_bytes: NSUInteger,
166            zone: *mut NSZone,
167        ) -> *mut AnyObject;
168    }
169    let ret = unsafe { NSCopyObject(object, extra_bytes, zone) };
170    unsafe { Retained::from_raw(ret) }
171        .expect("function was marked as returning non-null, but actually returned NULL")
172}
173
174/// # Safety
175///
176/// - `an_object` should be of the correct type.
177/// - `requested_zone` must be a valid pointer or null.
178#[cfg(feature = "NSZone")]
179#[inline]
180pub unsafe extern "C-unwind" fn NSShouldRetainWithZone(
181    an_object: &AnyObject,
182    requested_zone: *mut NSZone,
183) -> bool {
184    extern "C-unwind" {
185        fn NSShouldRetainWithZone(an_object: &AnyObject, requested_zone: *mut NSZone) -> Bool;
186    }
187    unsafe { NSShouldRetainWithZone(an_object, requested_zone) }.as_bool()
188}
189
190extern "C-unwind" {
191    /// # Safety
192    ///
193    /// `object` should be of the correct type.
194    pub fn NSIncrementExtraRefCount(object: &AnyObject);
195}
196
197/// # Safety
198///
199/// `object` should be of the correct type.
200#[inline]
201pub unsafe extern "C-unwind" fn NSDecrementExtraRefCountWasZero(object: &AnyObject) -> bool {
202    extern "C-unwind" {
203        fn NSDecrementExtraRefCountWasZero(object: &AnyObject) -> Bool;
204    }
205    unsafe { NSDecrementExtraRefCountWasZero(object) }.as_bool()
206}
207
208extern "C-unwind" {
209    /// # Safety
210    ///
211    /// `object` should be of the correct type.
212    pub fn NSExtraRefCount(object: &AnyObject) -> NSUInteger;
213}