objc2_foundation/generated/
NSHashTable.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
9/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nshashtablestrongmemory?language=objc)
10#[cfg(feature = "NSPointerFunctions")]
11pub static NSHashTableStrongMemory: NSPointerFunctionsOptions =
12    NSPointerFunctionsOptions(NSPointerFunctionsOptions::StrongMemory.0);
13
14/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nshashtablezeroingweakmemory?language=objc)
15#[cfg(feature = "NSPointerFunctions")]
16#[deprecated = "GC no longer supported"]
17pub static NSHashTableZeroingWeakMemory: NSPointerFunctionsOptions =
18    NSPointerFunctionsOptions(NSPointerFunctionsOptions::ZeroingWeakMemory.0);
19
20/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nshashtablecopyin?language=objc)
21#[cfg(feature = "NSPointerFunctions")]
22pub static NSHashTableCopyIn: NSPointerFunctionsOptions =
23    NSPointerFunctionsOptions(NSPointerFunctionsOptions::CopyIn.0);
24
25/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nshashtableobjectpointerpersonality?language=objc)
26#[cfg(feature = "NSPointerFunctions")]
27pub static NSHashTableObjectPointerPersonality: NSPointerFunctionsOptions =
28    NSPointerFunctionsOptions(NSPointerFunctionsOptions::ObjectPointerPersonality.0);
29
30/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nshashtableweakmemory?language=objc)
31#[cfg(feature = "NSPointerFunctions")]
32pub static NSHashTableWeakMemory: NSPointerFunctionsOptions =
33    NSPointerFunctionsOptions(NSPointerFunctionsOptions::WeakMemory.0);
34
35/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nshashtableoptions?language=objc)
36pub type NSHashTableOptions = NSUInteger;
37
38extern_class!(
39    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nshashtable?language=objc)
40    #[unsafe(super(NSObject))]
41    #[derive(Debug, PartialEq, Eq, Hash)]
42    pub struct NSHashTable<ObjectType: ?Sized = AnyObject>;
43);
44
45impl<ObjectType: ?Sized + Message> NSHashTable<ObjectType> {
46    /// Unchecked conversion of the generic parameter.
47    ///
48    /// # Safety
49    ///
50    /// The generic must be valid to reinterpret as the given type.
51    #[inline]
52    pub unsafe fn cast_unchecked<NewObjectType: ?Sized + Message>(
53        &self,
54    ) -> &NSHashTable<NewObjectType> {
55        unsafe { &*((self as *const Self).cast()) }
56    }
57}
58
59#[cfg(feature = "NSObject")]
60extern_conformance!(
61    unsafe impl<ObjectType: ?Sized + NSCoding> NSCoding for NSHashTable<ObjectType> {}
62);
63
64#[cfg(feature = "NSObject")]
65extern_conformance!(
66    unsafe impl<ObjectType: ?Sized> NSCopying for NSHashTable<ObjectType> {}
67);
68
69#[cfg(feature = "NSObject")]
70unsafe impl<ObjectType: ?Sized + Message> CopyingHelper for NSHashTable<ObjectType> {
71    type Result = Self;
72}
73
74#[cfg(feature = "NSEnumerator")]
75extern_conformance!(
76    unsafe impl<ObjectType: ?Sized> NSFastEnumeration for NSHashTable<ObjectType> {}
77);
78
79extern_conformance!(
80    unsafe impl<ObjectType: ?Sized> NSObjectProtocol for NSHashTable<ObjectType> {}
81);
82
83#[cfg(feature = "NSObject")]
84extern_conformance!(
85    unsafe impl<ObjectType: ?Sized + NSSecureCoding> NSSecureCoding for NSHashTable<ObjectType> {}
86);
87
88impl<ObjectType: Message> NSHashTable<ObjectType> {
89    extern_methods!(
90        #[cfg(feature = "NSPointerFunctions")]
91        #[unsafe(method(initWithOptions:capacity:))]
92        #[unsafe(method_family = init)]
93        pub fn initWithOptions_capacity(
94            this: Allocated<Self>,
95            options: NSPointerFunctionsOptions,
96            initial_capacity: NSUInteger,
97        ) -> Retained<Self>;
98
99        #[cfg(feature = "NSPointerFunctions")]
100        #[unsafe(method(initWithPointerFunctions:capacity:))]
101        #[unsafe(method_family = init)]
102        pub fn initWithPointerFunctions_capacity(
103            this: Allocated<Self>,
104            functions: &NSPointerFunctions,
105            initial_capacity: NSUInteger,
106        ) -> Retained<Self>;
107
108        #[cfg(feature = "NSPointerFunctions")]
109        #[unsafe(method(hashTableWithOptions:))]
110        #[unsafe(method_family = none)]
111        pub fn hashTableWithOptions(
112            options: NSPointerFunctionsOptions,
113        ) -> Retained<NSHashTable<ObjectType>>;
114
115        #[deprecated = "GC no longer supported"]
116        #[unsafe(method(hashTableWithWeakObjects))]
117        #[unsafe(method_family = none)]
118        pub fn hashTableWithWeakObjects() -> Retained<AnyObject>;
119
120        #[unsafe(method(weakObjectsHashTable))]
121        #[unsafe(method_family = none)]
122        pub fn weakObjectsHashTable() -> Retained<NSHashTable<ObjectType>>;
123
124        #[cfg(feature = "NSPointerFunctions")]
125        #[unsafe(method(pointerFunctions))]
126        #[unsafe(method_family = none)]
127        pub fn pointerFunctions(&self) -> Retained<NSPointerFunctions>;
128
129        #[unsafe(method(count))]
130        #[unsafe(method_family = none)]
131        pub fn count(&self) -> NSUInteger;
132
133        #[unsafe(method(member:))]
134        #[unsafe(method_family = none)]
135        pub fn member(&self, object: Option<&ObjectType>) -> Option<Retained<ObjectType>>;
136
137        #[cfg(feature = "NSEnumerator")]
138        /// # Safety
139        ///
140        /// The returned enumerator's underlying collection should not be mutated while in use.
141        #[unsafe(method(objectEnumerator))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn objectEnumerator(&self) -> Retained<NSEnumerator<ObjectType>>;
144
145        #[unsafe(method(addObject:))]
146        #[unsafe(method_family = none)]
147        pub fn addObject(&self, object: Option<&ObjectType>);
148
149        #[unsafe(method(removeObject:))]
150        #[unsafe(method_family = none)]
151        pub fn removeObject(&self, object: Option<&ObjectType>);
152
153        #[unsafe(method(removeAllObjects))]
154        #[unsafe(method_family = none)]
155        pub fn removeAllObjects(&self);
156
157        #[cfg(feature = "NSArray")]
158        #[unsafe(method(allObjects))]
159        #[unsafe(method_family = none)]
160        pub fn allObjects(&self) -> Retained<NSArray<ObjectType>>;
161
162        #[unsafe(method(anyObject))]
163        #[unsafe(method_family = none)]
164        pub fn anyObject(&self) -> Option<Retained<ObjectType>>;
165
166        #[unsafe(method(containsObject:))]
167        #[unsafe(method_family = none)]
168        pub fn containsObject(&self, an_object: Option<&ObjectType>) -> bool;
169
170        #[unsafe(method(intersectsHashTable:))]
171        #[unsafe(method_family = none)]
172        pub fn intersectsHashTable(&self, other: &NSHashTable<ObjectType>) -> bool;
173
174        #[unsafe(method(isEqualToHashTable:))]
175        #[unsafe(method_family = none)]
176        pub fn isEqualToHashTable(&self, other: &NSHashTable<ObjectType>) -> bool;
177
178        #[unsafe(method(isSubsetOfHashTable:))]
179        #[unsafe(method_family = none)]
180        pub fn isSubsetOfHashTable(&self, other: &NSHashTable<ObjectType>) -> bool;
181
182        #[unsafe(method(intersectHashTable:))]
183        #[unsafe(method_family = none)]
184        pub fn intersectHashTable(&self, other: &NSHashTable<ObjectType>);
185
186        #[unsafe(method(unionHashTable:))]
187        #[unsafe(method_family = none)]
188        pub fn unionHashTable(&self, other: &NSHashTable<ObjectType>);
189
190        #[unsafe(method(minusHashTable:))]
191        #[unsafe(method_family = none)]
192        pub fn minusHashTable(&self, other: &NSHashTable<ObjectType>);
193
194        #[cfg(feature = "NSSet")]
195        #[unsafe(method(setRepresentation))]
196        #[unsafe(method_family = none)]
197        pub fn setRepresentation(&self) -> Retained<NSSet<ObjectType>>;
198    );
199}
200
201/// Methods declared on superclass `NSObject`.
202impl<ObjectType: Message> NSHashTable<ObjectType> {
203    extern_methods!(
204        #[unsafe(method(init))]
205        #[unsafe(method_family = init)]
206        pub fn init(this: Allocated<Self>) -> Retained<Self>;
207
208        #[unsafe(method(new))]
209        #[unsafe(method_family = new)]
210        pub fn new() -> Retained<Self>;
211    );
212}
213
214impl<ObjectType: Message> DefaultRetained for NSHashTable<ObjectType> {
215    #[inline]
216    fn default_retained() -> Retained<Self> {
217        Self::new()
218    }
219}
220
221/// **************    (void *) Hash table operations    ***************
222///
223/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshashenumerator?language=objc)
224#[repr(C)]
225#[derive(Clone, Copy, Debug, PartialEq)]
226pub struct NSHashEnumerator {
227    pub(crate) _pi: NSUInteger,
228    pub(crate) _si: NSUInteger,
229    pub(crate) _bs: *mut c_void,
230}
231
232unsafe impl Encode for NSHashEnumerator {
233    const ENCODING: Encoding = Encoding::Struct(
234        "?",
235        &[
236            <NSUInteger>::ENCODING,
237            <NSUInteger>::ENCODING,
238            <*mut c_void>::ENCODING,
239        ],
240    );
241}
242
243unsafe impl RefEncode for NSHashEnumerator {
244    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
245}
246
247extern "C-unwind" {
248    /// # Safety
249    ///
250    /// `table` generic should be of the correct type.
251    pub fn NSFreeHashTable(table: &NSHashTable);
252}
253
254extern "C-unwind" {
255    /// # Safety
256    ///
257    /// `table` generic should be of the correct type.
258    pub fn NSResetHashTable(table: &NSHashTable);
259}
260
261/// # Safety
262///
263/// - `table1` generic should be of the correct type.
264/// - `table2` generic should be of the correct type.
265#[inline]
266pub unsafe extern "C-unwind" fn NSCompareHashTables(
267    table1: &NSHashTable,
268    table2: &NSHashTable,
269) -> bool {
270    extern "C-unwind" {
271        fn NSCompareHashTables(table1: &NSHashTable, table2: &NSHashTable) -> Bool;
272    }
273    unsafe { NSCompareHashTables(table1, table2) }.as_bool()
274}
275
276/// # Safety
277///
278/// - `table` generic should be of the correct type.
279/// - `zone` must be a valid pointer or null.
280#[cfg(feature = "NSZone")]
281#[inline]
282pub unsafe extern "C-unwind" fn NSCopyHashTableWithZone(
283    table: &NSHashTable,
284    zone: *mut NSZone,
285) -> Retained<NSHashTable> {
286    extern "C-unwind" {
287        fn NSCopyHashTableWithZone(table: &NSHashTable, zone: *mut NSZone) -> *mut NSHashTable;
288    }
289    let ret = unsafe { NSCopyHashTableWithZone(table, zone) };
290    unsafe { Retained::from_raw(ret) }
291        .expect("function was marked as returning non-null, but actually returned NULL")
292}
293
294/// # Safety
295///
296/// - `table` generic should be of the correct type.
297/// - `pointer` must be a valid pointer or null.
298#[inline]
299pub unsafe extern "C-unwind" fn NSHashGet(
300    table: &NSHashTable,
301    pointer: *const c_void,
302) -> NonNull<c_void> {
303    extern "C-unwind" {
304        fn NSHashGet(table: &NSHashTable, pointer: *const c_void) -> Option<NonNull<c_void>>;
305    }
306    let ret = unsafe { NSHashGet(table, pointer) };
307    ret.expect("function was marked as returning non-null, but actually returned NULL")
308}
309
310extern "C-unwind" {
311    /// # Safety
312    ///
313    /// - `table` generic should be of the correct type.
314    /// - `pointer` must be a valid pointer or null.
315    pub fn NSHashInsert(table: &NSHashTable, pointer: *const c_void);
316}
317
318extern "C-unwind" {
319    /// # Safety
320    ///
321    /// - `table` generic should be of the correct type.
322    /// - `pointer` must be a valid pointer or null.
323    pub fn NSHashInsertKnownAbsent(table: &NSHashTable, pointer: *const c_void);
324}
325
326extern "C-unwind" {
327    /// # Safety
328    ///
329    /// - `table` generic should be of the correct type.
330    /// - `pointer` must be a valid pointer or null.
331    pub fn NSHashInsertIfAbsent(table: &NSHashTable, pointer: *const c_void) -> *mut c_void;
332}
333
334extern "C-unwind" {
335    /// # Safety
336    ///
337    /// - `table` generic should be of the correct type.
338    /// - `pointer` must be a valid pointer or null.
339    pub fn NSHashRemove(table: &NSHashTable, pointer: *const c_void);
340}
341
342extern "C-unwind" {
343    /// # Safety
344    ///
345    /// `table` generic should be of the correct type.
346    pub fn NSEnumerateHashTable(table: &NSHashTable) -> NSHashEnumerator;
347}
348
349extern "C-unwind" {
350    /// # Safety
351    ///
352    /// `enumerator` must be a valid pointer.
353    pub fn NSNextHashEnumeratorItem(enumerator: NonNull<NSHashEnumerator>) -> *mut c_void;
354}
355
356extern "C-unwind" {
357    /// # Safety
358    ///
359    /// `enumerator` must be a valid pointer.
360    pub fn NSEndHashTableEnumeration(enumerator: NonNull<NSHashEnumerator>);
361}
362
363extern "C-unwind" {
364    /// # Safety
365    ///
366    /// `table` generic should be of the correct type.
367    pub fn NSCountHashTable(table: &NSHashTable) -> NSUInteger;
368}
369
370#[cfg(feature = "NSString")]
371impl NSString {
372    /// # Safety
373    ///
374    /// `table` generic should be of the correct type.
375    #[doc(alias = "NSStringFromHashTable")]
376    #[cfg(feature = "NSString")]
377    #[inline]
378    pub unsafe fn from_hash_table(table: &NSHashTable) -> Retained<NSString> {
379        extern "C-unwind" {
380            fn NSStringFromHashTable(table: &NSHashTable) -> *mut NSString;
381        }
382        let ret = unsafe { NSStringFromHashTable(table) };
383        unsafe { Retained::retain_autoreleased(ret) }
384            .expect("function was marked as returning non-null, but actually returned NULL")
385    }
386}
387
388/// # Safety
389///
390/// `table` generic should be of the correct type.
391#[cfg(feature = "NSArray")]
392#[inline]
393pub unsafe extern "C-unwind" fn NSAllHashTableObjects(table: &NSHashTable) -> Retained<NSArray> {
394    extern "C-unwind" {
395        fn NSAllHashTableObjects(table: &NSHashTable) -> *mut NSArray;
396    }
397    let ret = unsafe { NSAllHashTableObjects(table) };
398    unsafe { Retained::retain_autoreleased(ret) }
399        .expect("function was marked as returning non-null, but actually returned NULL")
400}
401
402/// **************    Legacy    ***************
403///
404/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nshashtablecallbacks?language=objc)
405#[cfg(feature = "NSString")]
406#[repr(C)]
407#[allow(unpredictable_function_pointer_comparisons)]
408#[derive(Clone, Copy, Debug, PartialEq)]
409pub struct NSHashTableCallBacks {
410    pub hash:
411        Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>) -> NSUInteger>,
412    pub isEqual: Option<
413        unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>, NonNull<c_void>) -> Bool,
414    >,
415    pub retain: Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>)>,
416    pub release: Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>)>,
417    pub describe:
418        Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>) -> *mut NSString>,
419}
420
421#[cfg(feature = "NSString")]
422unsafe impl Encode for NSHashTableCallBacks {
423    const ENCODING: Encoding = Encoding::Struct(
424        "?",
425        &[
426            <Option<
427                unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>) -> NSUInteger,
428            >>::ENCODING,
429            <Option<
430                unsafe extern "C-unwind" fn(
431                    NonNull<NSHashTable>,
432                    NonNull<c_void>,
433                    NonNull<c_void>,
434                ) -> Bool,
435            >>::ENCODING,
436            <Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>)>>::ENCODING,
437            <Option<unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>)>>::ENCODING,
438            <Option<
439                unsafe extern "C-unwind" fn(NonNull<NSHashTable>, NonNull<c_void>) -> *mut NSString,
440            >>::ENCODING,
441        ],
442    );
443}
444
445#[cfg(feature = "NSString")]
446unsafe impl RefEncode for NSHashTableCallBacks {
447    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
448}
449
450/// # Safety
451///
452/// - `call_backs` struct field 1 must be implemented correctly.
453/// - `call_backs` struct field 2 must be implemented correctly.
454/// - `call_backs` struct field 3 must be implemented correctly.
455/// - `call_backs` struct field 4 must be implemented correctly.
456/// - `call_backs` struct field 5 must be implemented correctly.
457/// - `zone` must be a valid pointer or null.
458#[cfg(all(feature = "NSString", feature = "NSZone"))]
459#[inline]
460pub unsafe extern "C-unwind" fn NSCreateHashTableWithZone(
461    call_backs: NSHashTableCallBacks,
462    capacity: NSUInteger,
463    zone: *mut NSZone,
464) -> Retained<NSHashTable> {
465    extern "C-unwind" {
466        fn NSCreateHashTableWithZone(
467            call_backs: NSHashTableCallBacks,
468            capacity: NSUInteger,
469            zone: *mut NSZone,
470        ) -> *mut NSHashTable;
471    }
472    let ret = unsafe { NSCreateHashTableWithZone(call_backs, capacity, zone) };
473    unsafe { Retained::from_raw(ret) }
474        .expect("function was marked as returning non-null, but actually returned NULL")
475}
476
477/// # Safety
478///
479/// - `call_backs` struct field 1 must be implemented correctly.
480/// - `call_backs` struct field 2 must be implemented correctly.
481/// - `call_backs` struct field 3 must be implemented correctly.
482/// - `call_backs` struct field 4 must be implemented correctly.
483/// - `call_backs` struct field 5 must be implemented correctly.
484#[cfg(feature = "NSString")]
485#[inline]
486pub unsafe extern "C-unwind" fn NSCreateHashTable(
487    call_backs: NSHashTableCallBacks,
488    capacity: NSUInteger,
489) -> Retained<NSHashTable> {
490    extern "C-unwind" {
491        fn NSCreateHashTable(
492            call_backs: NSHashTableCallBacks,
493            capacity: NSUInteger,
494        ) -> *mut NSHashTable;
495    }
496    let ret = unsafe { NSCreateHashTable(call_backs, capacity) };
497    unsafe { Retained::from_raw(ret) }
498        .expect("function was marked as returning non-null, but actually returned NULL")
499}
500
501extern "C" {
502    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsintegerhashcallbacks?language=objc)
503    #[cfg(feature = "NSString")]
504    pub static NSIntegerHashCallBacks: NSHashTableCallBacks;
505}
506
507extern "C" {
508    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnonownedpointerhashcallbacks?language=objc)
509    #[cfg(feature = "NSString")]
510    pub static NSNonOwnedPointerHashCallBacks: NSHashTableCallBacks;
511}
512
513extern "C" {
514    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnonretainedobjecthashcallbacks?language=objc)
515    #[cfg(feature = "NSString")]
516    pub static NSNonRetainedObjectHashCallBacks: NSHashTableCallBacks;
517}
518
519extern "C" {
520    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsobjecthashcallbacks?language=objc)
521    #[cfg(feature = "NSString")]
522    pub static NSObjectHashCallBacks: NSHashTableCallBacks;
523}
524
525extern "C" {
526    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsownedobjectidentityhashcallbacks?language=objc)
527    #[cfg(feature = "NSString")]
528    pub static NSOwnedObjectIdentityHashCallBacks: NSHashTableCallBacks;
529}
530
531extern "C" {
532    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsownedpointerhashcallbacks?language=objc)
533    #[cfg(feature = "NSString")]
534    pub static NSOwnedPointerHashCallBacks: NSHashTableCallBacks;
535}
536
537extern "C" {
538    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nspointertostructhashcallbacks?language=objc)
539    #[cfg(feature = "NSString")]
540    pub static NSPointerToStructHashCallBacks: NSHashTableCallBacks;
541}
542
543extern "C" {
544    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsinthashcallbacks?language=objc)
545    #[cfg(feature = "NSString")]
546    #[deprecated = "Not supported"]
547    pub static NSIntHashCallBacks: NSHashTableCallBacks;
548}
549
550#[cfg(feature = "NSString")]
551#[deprecated = "renamed to `NSString::from_hash_table`"]
552#[inline]
553pub unsafe extern "C-unwind" fn NSStringFromHashTable(table: &NSHashTable) -> Retained<NSString> {
554    extern "C-unwind" {
555        fn NSStringFromHashTable(table: &NSHashTable) -> *mut NSString;
556    }
557    let ret = unsafe { NSStringFromHashTable(table) };
558    unsafe { Retained::retain_autoreleased(ret) }
559        .expect("function was marked as returning non-null, but actually returned NULL")
560}