objc2-core-location 0.3.2

Bindings to the CoreLocation framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
//! Inlined from the underscore-named framework _LocationEssentials, was moved
//! from CoreLocation to there in Xcode 26, but it probably intended to be a
//! private implementation detail.
//!
//! Find it with:
//! ```sh
//! ls $(xcrun --show-sdk-path)/System/Library/Frameworks/_LocationEssentials.framework/Headers/CLLocationEssentials.h
//! ```
#![allow(non_snake_case, unused_imports)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::too_many_arguments)]
use core::ffi::c_double;
use core::ptr::NonNull;
use objc2::encode::{Encode, Encoding, RefEncode};
use objc2::rc::{Allocated, Retained};
use objc2::runtime::Bool;
use objc2::{extern_class, extern_conformance, extern_methods};
use objc2_foundation::{
    CopyingHelper, NSCoding, NSCopying, NSDate, NSInteger, NSObject, NSObjectProtocol,
    NSSecureCoding, NSTimeInterval,
};

/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdegrees?language=objc)
pub type CLLocationDegrees = c_double;

/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationaccuracy?language=objc)
pub type CLLocationAccuracy = c_double;

/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationspeed?language=objc)
pub type CLLocationSpeed = c_double;

/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationspeedaccuracy?language=objc)
pub type CLLocationSpeedAccuracy = c_double;

/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdirection?language=objc)
pub type CLLocationDirection = c_double;

/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdirectionaccuracy?language=objc)
pub type CLLocationDirectionAccuracy = c_double;

/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationcoordinate2d?language=objc)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CLLocationCoordinate2D {
    pub latitude: CLLocationDegrees,
    pub longitude: CLLocationDegrees,
}

unsafe impl Encode for CLLocationCoordinate2D {
    const ENCODING: Encoding = Encoding::Struct(
        "CLLocationCoordinate2D",
        &[<CLLocationDegrees>::ENCODING, <CLLocationDegrees>::ENCODING],
    );
}

unsafe impl RefEncode for CLLocationCoordinate2D {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdistance?language=objc)
pub type CLLocationDistance = c_double;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcldistancefilternone?language=objc)
    pub static kCLDistanceFilterNone: CLLocationDistance;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracybestfornavigation?language=objc)
    pub static kCLLocationAccuracyBestForNavigation: CLLocationAccuracy;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracybest?language=objc)
    pub static kCLLocationAccuracyBest: CLLocationAccuracy;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracynearesttenmeters?language=objc)
    pub static kCLLocationAccuracyNearestTenMeters: CLLocationAccuracy;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracyhundredmeters?language=objc)
    pub static kCLLocationAccuracyHundredMeters: CLLocationAccuracy;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracykilometer?language=objc)
    pub static kCLLocationAccuracyKilometer: CLLocationAccuracy;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracythreekilometers?language=objc)
    pub static kCLLocationAccuracyThreeKilometers: CLLocationAccuracy;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracyreduced?language=objc)
    pub static kCLLocationAccuracyReduced: CLLocationAccuracy;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdistancemax?language=objc)
    pub static CLLocationDistanceMax: CLLocationDistance;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cltimeintervalmax?language=objc)
    pub static CLTimeIntervalMax: NSTimeInterval;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationcoordinate2dinvalid?language=objc)
    pub static kCLLocationCoordinate2DInvalid: CLLocationCoordinate2D;
}

impl CLLocationCoordinate2D {
    #[doc(alias = "CLLocationCoordinate2DIsValid")]
    #[inline]
    pub unsafe fn is_valid(self) -> bool {
        extern "C-unwind" {
            fn CLLocationCoordinate2DIsValid(coord: CLLocationCoordinate2D) -> Bool;
        }
        unsafe { CLLocationCoordinate2DIsValid(self) }.as_bool()
    }

    #[doc(alias = "CLLocationCoordinate2DMake")]
    #[inline]
    pub unsafe fn new(
        latitude: CLLocationDegrees,
        longitude: CLLocationDegrees,
    ) -> CLLocationCoordinate2D {
        extern "C-unwind" {
            fn CLLocationCoordinate2DMake(
                latitude: CLLocationDegrees,
                longitude: CLLocationDegrees,
            ) -> CLLocationCoordinate2D;
        }
        unsafe { CLLocationCoordinate2DMake(latitude, longitude) }
    }
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/clfloor?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CLFloor;
);

extern_conformance!(
    unsafe impl NSCoding for CLFloor {}
);

extern_conformance!(
    unsafe impl NSCopying for CLFloor {}
);

unsafe impl CopyingHelper for CLFloor {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for CLFloor {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for CLFloor {}
);

impl CLFloor {
    extern_methods!(
        #[unsafe(method(level))]
        #[unsafe(method_family = none)]
        pub unsafe fn level(&self) -> NSInteger;
    );
}

/// Methods declared on superclass `NSObject`.
impl CLFloor {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationsourceinformation?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CLLocationSourceInformation;
);

extern_conformance!(
    unsafe impl NSCoding for CLLocationSourceInformation {}
);

extern_conformance!(
    unsafe impl NSCopying for CLLocationSourceInformation {}
);

unsafe impl CopyingHelper for CLLocationSourceInformation {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for CLLocationSourceInformation {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for CLLocationSourceInformation {}
);

impl CLLocationSourceInformation {
    extern_methods!(
        #[unsafe(method(initWithSoftwareSimulationState:andExternalAccessoryState:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithSoftwareSimulationState_andExternalAccessoryState(
            this: Allocated<Self>,
            is_software: bool,
            is_accessory: bool,
        ) -> Retained<Self>;

        #[unsafe(method(isSimulatedBySoftware))]
        #[unsafe(method_family = none)]
        pub unsafe fn isSimulatedBySoftware(&self) -> bool;

        #[unsafe(method(isProducedByAccessory))]
        #[unsafe(method_family = none)]
        pub unsafe fn isProducedByAccessory(&self) -> bool;
    );
}

/// Methods declared on superclass `NSObject`.
impl CLLocationSourceInformation {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocation?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CLLocation;
);

unsafe impl Send for CLLocation {}

unsafe impl Sync for CLLocation {}

extern_conformance!(
    unsafe impl NSCoding for CLLocation {}
);

extern_conformance!(
    unsafe impl NSCopying for CLLocation {}
);

unsafe impl CopyingHelper for CLLocation {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for CLLocation {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for CLLocation {}
);

impl CLLocation {
    extern_methods!(
        #[unsafe(method(initWithLatitude:longitude:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithLatitude_longitude(
            this: Allocated<Self>,
            latitude: CLLocationDegrees,
            longitude: CLLocationDegrees,
        ) -> Retained<Self>;

        #[unsafe(method(initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:timestamp:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoordinate_altitude_horizontalAccuracy_verticalAccuracy_timestamp(
            this: Allocated<Self>,
            coordinate: CLLocationCoordinate2D,
            altitude: CLLocationDistance,
            h_accuracy: CLLocationAccuracy,
            v_accuracy: CLLocationAccuracy,
            timestamp: &NSDate,
        ) -> Retained<Self>;

        #[unsafe(method(initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:course:speed:timestamp:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoordinate_altitude_horizontalAccuracy_verticalAccuracy_course_speed_timestamp(
            this: Allocated<Self>,
            coordinate: CLLocationCoordinate2D,
            altitude: CLLocationDistance,
            h_accuracy: CLLocationAccuracy,
            v_accuracy: CLLocationAccuracy,
            course: CLLocationDirection,
            speed: CLLocationSpeed,
            timestamp: &NSDate,
        ) -> Retained<Self>;

        #[unsafe(method(initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:course:courseAccuracy:speed:speedAccuracy:timestamp:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoordinate_altitude_horizontalAccuracy_verticalAccuracy_course_courseAccuracy_speed_speedAccuracy_timestamp(
            this: Allocated<Self>,
            coordinate: CLLocationCoordinate2D,
            altitude: CLLocationDistance,
            h_accuracy: CLLocationAccuracy,
            v_accuracy: CLLocationAccuracy,
            course: CLLocationDirection,
            course_accuracy: CLLocationDirectionAccuracy,
            speed: CLLocationSpeed,
            speed_accuracy: CLLocationSpeedAccuracy,
            timestamp: &NSDate,
        ) -> Retained<Self>;

        #[unsafe(method(initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:course:courseAccuracy:speed:speedAccuracy:timestamp:sourceInfo:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoordinate_altitude_horizontalAccuracy_verticalAccuracy_course_courseAccuracy_speed_speedAccuracy_timestamp_sourceInfo(
            this: Allocated<Self>,
            coordinate: CLLocationCoordinate2D,
            altitude: CLLocationDistance,
            h_accuracy: CLLocationAccuracy,
            v_accuracy: CLLocationAccuracy,
            course: CLLocationDirection,
            course_accuracy: CLLocationDirectionAccuracy,
            speed: CLLocationSpeed,
            speed_accuracy: CLLocationSpeedAccuracy,
            timestamp: &NSDate,
            source_info: &CLLocationSourceInformation,
        ) -> Retained<Self>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(coordinate))]
        #[unsafe(method_family = none)]
        pub unsafe fn coordinate(&self) -> CLLocationCoordinate2D;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(altitude))]
        #[unsafe(method_family = none)]
        pub unsafe fn altitude(&self) -> CLLocationDistance;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(ellipsoidalAltitude))]
        #[unsafe(method_family = none)]
        pub unsafe fn ellipsoidalAltitude(&self) -> CLLocationDistance;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(horizontalAccuracy))]
        #[unsafe(method_family = none)]
        pub unsafe fn horizontalAccuracy(&self) -> CLLocationAccuracy;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(verticalAccuracy))]
        #[unsafe(method_family = none)]
        pub unsafe fn verticalAccuracy(&self) -> CLLocationAccuracy;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(course))]
        #[unsafe(method_family = none)]
        pub unsafe fn course(&self) -> CLLocationDirection;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(courseAccuracy))]
        #[unsafe(method_family = none)]
        pub unsafe fn courseAccuracy(&self) -> CLLocationDirectionAccuracy;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(speed))]
        #[unsafe(method_family = none)]
        pub unsafe fn speed(&self) -> CLLocationSpeed;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(speedAccuracy))]
        #[unsafe(method_family = none)]
        pub unsafe fn speedAccuracy(&self) -> CLLocationSpeedAccuracy;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(timestamp))]
        #[unsafe(method_family = none)]
        pub unsafe fn timestamp(&self) -> Retained<NSDate>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(floor))]
        #[unsafe(method_family = none)]
        pub unsafe fn floor(&self) -> Option<Retained<CLFloor>>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(sourceInformation))]
        #[unsafe(method_family = none)]
        pub unsafe fn sourceInformation(&self) -> Option<Retained<CLLocationSourceInformation>>;

        #[deprecated]
        #[unsafe(method(getDistanceFrom:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getDistanceFrom(&self, location: &CLLocation) -> CLLocationDistance;

        #[unsafe(method(distanceFromLocation:))]
        #[unsafe(method_family = none)]
        pub unsafe fn distanceFromLocation(&self, location: &CLLocation) -> CLLocationDistance;
    );
}

/// Methods declared on superclass `NSObject`.
impl CLLocation {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

#[deprecated = "renamed to `CLLocationCoordinate2D::is_valid`"]
#[inline]
pub unsafe extern "C-unwind" fn CLLocationCoordinate2DIsValid(
    coord: CLLocationCoordinate2D,
) -> bool {
    extern "C-unwind" {
        fn CLLocationCoordinate2DIsValid(coord: CLLocationCoordinate2D) -> Bool;
    }
    unsafe { CLLocationCoordinate2DIsValid(coord) }.as_bool()
}

extern "C-unwind" {
    #[deprecated = "renamed to `CLLocationCoordinate2D::new`"]
    pub fn CLLocationCoordinate2DMake(
        latitude: CLLocationDegrees,
        longitude: CLLocationDegrees,
    ) -> CLLocationCoordinate2D;
}