objc2_foundation/generated/
NSFileHandle.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_class!(
10    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilehandle?language=objc)
11    #[unsafe(super(NSObject))]
12    #[derive(Debug, PartialEq, Eq, Hash)]
13    pub struct NSFileHandle;
14);
15
16unsafe impl Send for NSFileHandle {}
17
18unsafe impl Sync for NSFileHandle {}
19
20#[cfg(feature = "NSObject")]
21extern_conformance!(
22    unsafe impl NSCoding for NSFileHandle {}
23);
24
25extern_conformance!(
26    unsafe impl NSObjectProtocol for NSFileHandle {}
27);
28
29#[cfg(feature = "NSObject")]
30extern_conformance!(
31    unsafe impl NSSecureCoding for NSFileHandle {}
32);
33
34impl NSFileHandle {
35    extern_methods!(
36        #[cfg(feature = "NSData")]
37        #[unsafe(method(availableData))]
38        #[unsafe(method_family = none)]
39        pub fn availableData(&self) -> Retained<NSData>;
40
41        #[unsafe(method(initWithFileDescriptor:closeOnDealloc:))]
42        #[unsafe(method_family = init)]
43        pub fn initWithFileDescriptor_closeOnDealloc(
44            this: Allocated<Self>,
45            fd: c_int,
46            closeopt: bool,
47        ) -> Retained<Self>;
48
49        #[cfg(feature = "NSCoder")]
50        /// # Safety
51        ///
52        /// `coder` possibly has further requirements.
53        #[unsafe(method(initWithCoder:))]
54        #[unsafe(method_family = init)]
55        pub unsafe fn initWithCoder(
56            this: Allocated<Self>,
57            coder: &NSCoder,
58        ) -> Option<Retained<Self>>;
59
60        #[cfg(all(feature = "NSData", feature = "NSError"))]
61        #[unsafe(method(readDataToEndOfFileAndReturnError:_))]
62        #[unsafe(method_family = none)]
63        pub fn readDataToEndOfFileAndReturnError(
64            &self,
65        ) -> Result<Retained<NSData>, Retained<NSError>>;
66
67        #[cfg(all(feature = "NSData", feature = "NSError"))]
68        #[unsafe(method(readDataUpToLength:error:_))]
69        #[unsafe(method_family = none)]
70        pub fn readDataUpToLength_error(
71            &self,
72            length: NSUInteger,
73        ) -> Result<Retained<NSData>, Retained<NSError>>;
74
75        #[cfg(all(feature = "NSData", feature = "NSError"))]
76        #[unsafe(method(writeData:error:_))]
77        #[unsafe(method_family = none)]
78        pub fn writeData_error(&self, data: &NSData) -> Result<(), Retained<NSError>>;
79
80        #[cfg(feature = "NSError")]
81        /// # Safety
82        ///
83        /// `offset_in_file` must be a valid pointer.
84        #[unsafe(method(getOffset:error:_))]
85        #[unsafe(method_family = none)]
86        pub unsafe fn getOffset_error(
87            &self,
88            offset_in_file: NonNull<c_ulonglong>,
89        ) -> Result<(), Retained<NSError>>;
90
91        #[cfg(feature = "NSError")]
92        /// # Safety
93        ///
94        /// `offset_in_file` must be a valid pointer or null.
95        #[unsafe(method(seekToEndReturningOffset:error:_))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn seekToEndReturningOffset_error(
98            &self,
99            offset_in_file: *mut c_ulonglong,
100        ) -> Result<(), Retained<NSError>>;
101
102        #[cfg(feature = "NSError")]
103        #[unsafe(method(seekToOffset:error:_))]
104        #[unsafe(method_family = none)]
105        pub fn seekToOffset_error(&self, offset: c_ulonglong) -> Result<(), Retained<NSError>>;
106
107        #[cfg(feature = "NSError")]
108        #[unsafe(method(truncateAtOffset:error:_))]
109        #[unsafe(method_family = none)]
110        pub fn truncateAtOffset_error(&self, offset: c_ulonglong) -> Result<(), Retained<NSError>>;
111
112        #[cfg(feature = "NSError")]
113        #[unsafe(method(synchronizeAndReturnError:_))]
114        #[unsafe(method_family = none)]
115        pub fn synchronizeAndReturnError(&self) -> Result<(), Retained<NSError>>;
116
117        #[cfg(feature = "NSError")]
118        #[unsafe(method(closeAndReturnError:_))]
119        #[unsafe(method_family = none)]
120        pub fn closeAndReturnError(&self) -> Result<(), Retained<NSError>>;
121    );
122}
123
124/// Methods declared on superclass `NSObject`.
125impl NSFileHandle {
126    extern_methods!(
127        #[unsafe(method(init))]
128        #[unsafe(method_family = init)]
129        pub fn init(this: Allocated<Self>) -> Retained<Self>;
130
131        #[unsafe(method(new))]
132        #[unsafe(method_family = new)]
133        pub fn new() -> Retained<Self>;
134    );
135}
136
137impl DefaultRetained for NSFileHandle {
138    #[inline]
139    fn default_retained() -> Retained<Self> {
140        Self::new()
141    }
142}
143
144/// NSFileHandleCreation.
145impl NSFileHandle {
146    extern_methods!(
147        #[unsafe(method(fileHandleWithStandardInput))]
148        #[unsafe(method_family = none)]
149        pub fn fileHandleWithStandardInput() -> Retained<NSFileHandle>;
150
151        #[unsafe(method(fileHandleWithStandardOutput))]
152        #[unsafe(method_family = none)]
153        pub fn fileHandleWithStandardOutput() -> Retained<NSFileHandle>;
154
155        #[unsafe(method(fileHandleWithStandardError))]
156        #[unsafe(method_family = none)]
157        pub fn fileHandleWithStandardError() -> Retained<NSFileHandle>;
158
159        #[unsafe(method(fileHandleWithNullDevice))]
160        #[unsafe(method_family = none)]
161        pub fn fileHandleWithNullDevice() -> Retained<NSFileHandle>;
162
163        #[cfg(feature = "NSString")]
164        #[unsafe(method(fileHandleForReadingAtPath:))]
165        #[unsafe(method_family = none)]
166        pub fn fileHandleForReadingAtPath(path: &NSString) -> Option<Retained<Self>>;
167
168        #[cfg(feature = "NSString")]
169        #[unsafe(method(fileHandleForWritingAtPath:))]
170        #[unsafe(method_family = none)]
171        pub fn fileHandleForWritingAtPath(path: &NSString) -> Option<Retained<Self>>;
172
173        #[cfg(feature = "NSString")]
174        #[unsafe(method(fileHandleForUpdatingAtPath:))]
175        #[unsafe(method_family = none)]
176        pub fn fileHandleForUpdatingAtPath(path: &NSString) -> Option<Retained<Self>>;
177
178        #[cfg(all(feature = "NSError", feature = "NSURL"))]
179        #[unsafe(method(fileHandleForReadingFromURL:error:_))]
180        #[unsafe(method_family = none)]
181        pub fn fileHandleForReadingFromURL_error(
182            url: &NSURL,
183        ) -> Result<Retained<Self>, Retained<NSError>>;
184
185        #[cfg(all(feature = "NSError", feature = "NSURL"))]
186        #[unsafe(method(fileHandleForWritingToURL:error:_))]
187        #[unsafe(method_family = none)]
188        pub fn fileHandleForWritingToURL_error(
189            url: &NSURL,
190        ) -> Result<Retained<Self>, Retained<NSError>>;
191
192        #[cfg(all(feature = "NSError", feature = "NSURL"))]
193        #[unsafe(method(fileHandleForUpdatingURL:error:_))]
194        #[unsafe(method_family = none)]
195        pub fn fileHandleForUpdatingURL_error(
196            url: &NSURL,
197        ) -> Result<Retained<Self>, Retained<NSError>>;
198    );
199}
200
201extern "C" {
202    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilehandleoperationexception?language=objc)
203    #[cfg(all(feature = "NSObjCRuntime", feature = "NSString"))]
204    pub static NSFileHandleOperationException: &'static NSExceptionName;
205}
206
207extern "C" {
208    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilehandlereadcompletionnotification?language=objc)
209    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
210    pub static NSFileHandleReadCompletionNotification: &'static NSNotificationName;
211}
212
213extern "C" {
214    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilehandlereadtoendoffilecompletionnotification?language=objc)
215    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
216    pub static NSFileHandleReadToEndOfFileCompletionNotification: &'static NSNotificationName;
217}
218
219extern "C" {
220    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilehandleconnectionacceptednotification?language=objc)
221    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
222    pub static NSFileHandleConnectionAcceptedNotification: &'static NSNotificationName;
223}
224
225extern "C" {
226    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilehandledataavailablenotification?language=objc)
227    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
228    pub static NSFileHandleDataAvailableNotification: &'static NSNotificationName;
229}
230
231extern "C" {
232    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilehandlenotificationdataitem?language=objc)
233    #[cfg(feature = "NSString")]
234    pub static NSFileHandleNotificationDataItem: &'static NSString;
235}
236
237extern "C" {
238    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilehandlenotificationfilehandleitem?language=objc)
239    #[cfg(feature = "NSString")]
240    pub static NSFileHandleNotificationFileHandleItem: &'static NSString;
241}
242
243extern "C" {
244    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilehandlenotificationmonitormodes?language=objc)
245    #[cfg(feature = "NSString")]
246    #[deprecated = "Not supported"]
247    pub static NSFileHandleNotificationMonitorModes: &'static NSString;
248}
249
250/// NSFileHandleAsynchronousAccess.
251impl NSFileHandle {
252    extern_methods!(
253        #[cfg(all(feature = "NSArray", feature = "NSObjCRuntime", feature = "NSString"))]
254        #[unsafe(method(readInBackgroundAndNotifyForModes:))]
255        #[unsafe(method_family = none)]
256        pub fn readInBackgroundAndNotifyForModes(&self, modes: Option<&NSArray<NSRunLoopMode>>);
257
258        #[unsafe(method(readInBackgroundAndNotify))]
259        #[unsafe(method_family = none)]
260        pub fn readInBackgroundAndNotify(&self);
261
262        #[cfg(all(feature = "NSArray", feature = "NSObjCRuntime", feature = "NSString"))]
263        #[unsafe(method(readToEndOfFileInBackgroundAndNotifyForModes:))]
264        #[unsafe(method_family = none)]
265        pub fn readToEndOfFileInBackgroundAndNotifyForModes(
266            &self,
267            modes: Option<&NSArray<NSRunLoopMode>>,
268        );
269
270        #[unsafe(method(readToEndOfFileInBackgroundAndNotify))]
271        #[unsafe(method_family = none)]
272        pub fn readToEndOfFileInBackgroundAndNotify(&self);
273
274        #[cfg(all(feature = "NSArray", feature = "NSObjCRuntime", feature = "NSString"))]
275        #[unsafe(method(acceptConnectionInBackgroundAndNotifyForModes:))]
276        #[unsafe(method_family = none)]
277        pub fn acceptConnectionInBackgroundAndNotifyForModes(
278            &self,
279            modes: Option<&NSArray<NSRunLoopMode>>,
280        );
281
282        #[unsafe(method(acceptConnectionInBackgroundAndNotify))]
283        #[unsafe(method_family = none)]
284        pub fn acceptConnectionInBackgroundAndNotify(&self);
285
286        #[cfg(all(feature = "NSArray", feature = "NSObjCRuntime", feature = "NSString"))]
287        #[unsafe(method(waitForDataInBackgroundAndNotifyForModes:))]
288        #[unsafe(method_family = none)]
289        pub fn waitForDataInBackgroundAndNotifyForModes(
290            &self,
291            modes: Option<&NSArray<NSRunLoopMode>>,
292        );
293
294        #[unsafe(method(waitForDataInBackgroundAndNotify))]
295        #[unsafe(method_family = none)]
296        pub fn waitForDataInBackgroundAndNotify(&self);
297
298        #[cfg(feature = "block2")]
299        /// # Safety
300        ///
301        /// The returned block must be sendable.
302        #[unsafe(method(readabilityHandler))]
303        #[unsafe(method_family = none)]
304        pub unsafe fn readabilityHandler(
305            &self,
306        ) -> *mut block2::DynBlock<dyn Fn(NonNull<NSFileHandle>)>;
307
308        #[cfg(feature = "block2")]
309        /// Setter for [`readabilityHandler`][Self::readabilityHandler].
310        ///
311        /// This is [copied][crate::NSCopying::copy] when set.
312        ///
313        /// # Safety
314        ///
315        /// `readability_handler` block must be sendable.
316        #[unsafe(method(setReadabilityHandler:))]
317        #[unsafe(method_family = none)]
318        pub unsafe fn setReadabilityHandler(
319            &self,
320            readability_handler: Option<&block2::DynBlock<dyn Fn(NonNull<NSFileHandle>)>>,
321        );
322
323        #[cfg(feature = "block2")]
324        /// # Safety
325        ///
326        /// The returned block must be sendable.
327        #[unsafe(method(writeabilityHandler))]
328        #[unsafe(method_family = none)]
329        pub unsafe fn writeabilityHandler(
330            &self,
331        ) -> *mut block2::DynBlock<dyn Fn(NonNull<NSFileHandle>)>;
332
333        #[cfg(feature = "block2")]
334        /// Setter for [`writeabilityHandler`][Self::writeabilityHandler].
335        ///
336        /// This is [copied][crate::NSCopying::copy] when set.
337        ///
338        /// # Safety
339        ///
340        /// `writeability_handler` block must be sendable.
341        #[unsafe(method(setWriteabilityHandler:))]
342        #[unsafe(method_family = none)]
343        pub unsafe fn setWriteabilityHandler(
344            &self,
345            writeability_handler: Option<&block2::DynBlock<dyn Fn(NonNull<NSFileHandle>)>>,
346        );
347    );
348}
349
350/// NSFileHandlePlatformSpecific.
351impl NSFileHandle {
352    extern_methods!(
353        #[unsafe(method(initWithFileDescriptor:))]
354        #[unsafe(method_family = init)]
355        pub fn initWithFileDescriptor(this: Allocated<Self>, fd: c_int) -> Retained<Self>;
356
357        #[unsafe(method(fileDescriptor))]
358        #[unsafe(method_family = none)]
359        pub fn fileDescriptor(&self) -> c_int;
360    );
361}
362
363impl NSFileHandle {
364    extern_methods!(
365        #[cfg(feature = "NSData")]
366        #[deprecated]
367        #[unsafe(method(readDataToEndOfFile))]
368        #[unsafe(method_family = none)]
369        pub fn readDataToEndOfFile(&self) -> Retained<NSData>;
370
371        #[cfg(feature = "NSData")]
372        #[deprecated]
373        #[unsafe(method(readDataOfLength:))]
374        #[unsafe(method_family = none)]
375        pub fn readDataOfLength(&self, length: NSUInteger) -> Retained<NSData>;
376
377        #[cfg(feature = "NSData")]
378        #[deprecated]
379        #[unsafe(method(writeData:))]
380        #[unsafe(method_family = none)]
381        pub fn writeData(&self, data: &NSData);
382
383        #[deprecated]
384        #[unsafe(method(offsetInFile))]
385        #[unsafe(method_family = none)]
386        pub fn offsetInFile(&self) -> c_ulonglong;
387
388        #[deprecated]
389        #[unsafe(method(seekToEndOfFile))]
390        #[unsafe(method_family = none)]
391        pub fn seekToEndOfFile(&self) -> c_ulonglong;
392
393        #[deprecated]
394        #[unsafe(method(seekToFileOffset:))]
395        #[unsafe(method_family = none)]
396        pub fn seekToFileOffset(&self, offset: c_ulonglong);
397
398        #[deprecated]
399        #[unsafe(method(truncateFileAtOffset:))]
400        #[unsafe(method_family = none)]
401        pub fn truncateFileAtOffset(&self, offset: c_ulonglong);
402
403        #[deprecated]
404        #[unsafe(method(synchronizeFile))]
405        #[unsafe(method_family = none)]
406        pub fn synchronizeFile(&self);
407
408        #[deprecated]
409        #[unsafe(method(closeFile))]
410        #[unsafe(method_family = none)]
411        pub fn closeFile(&self);
412    );
413}
414
415extern_class!(
416    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nspipe?language=objc)
417    #[unsafe(super(NSObject))]
418    #[derive(Debug, PartialEq, Eq, Hash)]
419    pub struct NSPipe;
420);
421
422unsafe impl Send for NSPipe {}
423
424unsafe impl Sync for NSPipe {}
425
426extern_conformance!(
427    unsafe impl NSObjectProtocol for NSPipe {}
428);
429
430impl NSPipe {
431    extern_methods!(
432        #[unsafe(method(fileHandleForReading))]
433        #[unsafe(method_family = none)]
434        pub fn fileHandleForReading(&self) -> Retained<NSFileHandle>;
435
436        #[unsafe(method(fileHandleForWriting))]
437        #[unsafe(method_family = none)]
438        pub fn fileHandleForWriting(&self) -> Retained<NSFileHandle>;
439
440        #[unsafe(method(pipe))]
441        #[unsafe(method_family = none)]
442        pub fn pipe() -> Retained<NSPipe>;
443    );
444}
445
446/// Methods declared on superclass `NSObject`.
447impl NSPipe {
448    extern_methods!(
449        #[unsafe(method(init))]
450        #[unsafe(method_family = init)]
451        pub fn init(this: Allocated<Self>) -> Retained<Self>;
452
453        #[unsafe(method(new))]
454        #[unsafe(method_family = new)]
455        pub fn new() -> Retained<Self>;
456    );
457}
458
459impl DefaultRetained for NSPipe {
460    #[inline]
461    fn default_retained() -> Retained<Self> {
462        Self::new()
463    }
464}