objc2_foundation/generated/
NSOrderedCollectionDifference.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5
6use crate::*;
7
8/// Options supported by methods that produce difference objects.
9///
10/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsorderedcollectiondifferencecalculationoptions?language=objc)
11// NS_OPTIONS
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct NSOrderedCollectionDifferenceCalculationOptions(pub NSUInteger);
15bitflags::bitflags! {
16    impl NSOrderedCollectionDifferenceCalculationOptions: NSUInteger {
17/// Insertion changes do not store a reference to the inserted object.
18        #[doc(alias = "NSOrderedCollectionDifferenceCalculationOmitInsertedObjects")]
19        const OmitInsertedObjects = 1<<0;
20/// Insertion changes do not store a reference to the removed object.
21        #[doc(alias = "NSOrderedCollectionDifferenceCalculationOmitRemovedObjects")]
22        const OmitRemovedObjects = 1<<1;
23/// Assume objects that were uniquely removed and inserted were moved.
24/// This is useful when diffing based on identity instead of equality.
25        #[doc(alias = "NSOrderedCollectionDifferenceCalculationInferMoves")]
26        const InferMoves = 1<<2;
27    }
28}
29
30unsafe impl Encode for NSOrderedCollectionDifferenceCalculationOptions {
31    const ENCODING: Encoding = NSUInteger::ENCODING;
32}
33
34unsafe impl RefEncode for NSOrderedCollectionDifferenceCalculationOptions {
35    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
36}
37
38extern_class!(
39    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsorderedcollectiondifference?language=objc)
40    #[unsafe(super(NSObject))]
41    #[derive(Debug, PartialEq, Eq, Hash)]
42    pub struct NSOrderedCollectionDifference<ObjectType: ?Sized = AnyObject>;
43);
44
45impl<ObjectType: ?Sized + Message> NSOrderedCollectionDifference<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    ) -> &NSOrderedCollectionDifference<NewObjectType> {
55        unsafe { &*((self as *const Self).cast()) }
56    }
57}
58
59#[cfg(feature = "NSEnumerator")]
60extern_conformance!(
61    unsafe impl<ObjectType: ?Sized> NSFastEnumeration for NSOrderedCollectionDifference<ObjectType> {}
62);
63
64extern_conformance!(
65    unsafe impl<ObjectType: ?Sized> NSObjectProtocol for NSOrderedCollectionDifference<ObjectType> {}
66);
67
68impl<ObjectType: Message> NSOrderedCollectionDifference<ObjectType> {
69    extern_methods!(
70        #[cfg(all(feature = "NSArray", feature = "NSOrderedCollectionChange"))]
71        /// Creates a new difference representing the changes in the parameter.
72        ///
73        /// For clients interested in the difference between two collections, the
74        /// collection's differenceFrom method should be used instead.
75        ///
76        /// To guarantee that instances are unambiguous and safe for compatible base
77        /// states, this method requires that its parameter conform to the following
78        /// requirements:
79        ///
80        /// 1) All insertion offsets are unique
81        /// 2) All removal offsets are unique
82        /// 3) All associated indexes match a change with the opposite parity.
83        #[unsafe(method(initWithChanges:))]
84        #[unsafe(method_family = init)]
85        pub fn initWithChanges(
86            this: Allocated<Self>,
87            changes: &NSArray<NSOrderedCollectionChange<ObjectType>>,
88        ) -> Retained<Self>;
89
90        #[cfg(all(
91            feature = "NSArray",
92            feature = "NSIndexSet",
93            feature = "NSOrderedCollectionChange"
94        ))]
95        #[unsafe(method(initWithInsertIndexes:insertedObjects:removeIndexes:removedObjects:additionalChanges:))]
96        #[unsafe(method_family = init)]
97        pub fn initWithInsertIndexes_insertedObjects_removeIndexes_removedObjects_additionalChanges(
98            this: Allocated<Self>,
99            inserts: &NSIndexSet,
100            inserted_objects: Option<&NSArray<ObjectType>>,
101            removes: &NSIndexSet,
102            removed_objects: Option<&NSArray<ObjectType>>,
103            changes: &NSArray<NSOrderedCollectionChange<ObjectType>>,
104        ) -> Retained<Self>;
105
106        #[cfg(all(feature = "NSArray", feature = "NSIndexSet"))]
107        #[unsafe(method(initWithInsertIndexes:insertedObjects:removeIndexes:removedObjects:))]
108        #[unsafe(method_family = init)]
109        pub fn initWithInsertIndexes_insertedObjects_removeIndexes_removedObjects(
110            this: Allocated<Self>,
111            inserts: &NSIndexSet,
112            inserted_objects: Option<&NSArray<ObjectType>>,
113            removes: &NSIndexSet,
114            removed_objects: Option<&NSArray<ObjectType>>,
115        ) -> Retained<Self>;
116
117        #[cfg(all(feature = "NSArray", feature = "NSOrderedCollectionChange"))]
118        #[unsafe(method(insertions))]
119        #[unsafe(method_family = none)]
120        pub fn insertions(&self) -> Retained<NSArray<NSOrderedCollectionChange<ObjectType>>>;
121
122        #[cfg(all(feature = "NSArray", feature = "NSOrderedCollectionChange"))]
123        #[unsafe(method(removals))]
124        #[unsafe(method_family = none)]
125        pub fn removals(&self) -> Retained<NSArray<NSOrderedCollectionChange<ObjectType>>>;
126
127        #[unsafe(method(hasChanges))]
128        #[unsafe(method_family = none)]
129        pub fn hasChanges(&self) -> bool;
130
131        #[cfg(all(feature = "NSOrderedCollectionChange", feature = "block2"))]
132        /// # Safety
133        ///
134        /// `block` block's return must be a valid pointer.
135        #[unsafe(method(differenceByTransformingChangesWithBlock:))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn differenceByTransformingChangesWithBlock(
138            &self,
139            block: &block2::DynBlock<
140                dyn Fn(
141                        NonNull<NSOrderedCollectionChange<ObjectType>>,
142                    ) -> NonNull<NSOrderedCollectionChange<AnyObject>>
143                    + '_,
144            >,
145        ) -> Retained<NSOrderedCollectionDifference<AnyObject>>;
146
147        #[unsafe(method(inverseDifference))]
148        #[unsafe(method_family = none)]
149        pub fn inverseDifference(&self) -> Retained<Self>;
150    );
151}
152
153/// Methods declared on superclass `NSObject`.
154impl<ObjectType: Message> NSOrderedCollectionDifference<ObjectType> {
155    extern_methods!(
156        #[unsafe(method(init))]
157        #[unsafe(method_family = init)]
158        pub fn init(this: Allocated<Self>) -> Retained<Self>;
159
160        #[unsafe(method(new))]
161        #[unsafe(method_family = new)]
162        pub fn new() -> Retained<Self>;
163    );
164}
165
166impl<ObjectType: Message> DefaultRetained for NSOrderedCollectionDifference<ObjectType> {
167    #[inline]
168    fn default_retained() -> Retained<Self> {
169        Self::new()
170    }
171}