1 // Copyright 2013 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9 
10 #![allow(non_upper_case_globals)]
11 
12 use std::ptr;
13 use std::os::raw::c_void;
14 use base::{id, BOOL, NO, SEL, nil};
15 use block::Block;
16 use libc;
17 
18 
19 #[cfg(target_pointer_width = "32")]
20 pub type NSInteger = libc::c_int;
21 #[cfg(target_pointer_width = "32")]
22 pub type NSUInteger = libc::c_uint;
23 
24 #[cfg(target_pointer_width = "64")]
25 pub type NSInteger = libc::c_long;
26 #[cfg(target_pointer_width = "64")]
27 pub type NSUInteger = libc::c_ulong;
28 
29 const UTF8_ENCODING: usize = 4;
30 
31 #[cfg(target_os = "macos")]
32 mod macos {
33     use std::mem;
34     use base::id;
35     use core_graphics::base::CGFloat;
36     use core_graphics::geometry::CGRect;
37     use objc;
38 
39     #[repr(C)]
40     #[derive(Copy, Clone)]
41     pub struct NSPoint {
42         pub x: f64,
43         pub y: f64,
44     }
45 
46     impl NSPoint {
47         #[inline]
new(x: f64, y: f64) -> NSPoint48         pub fn new(x: f64, y: f64) -> NSPoint {
49             NSPoint {
50                 x: x,
51                 y: y,
52             }
53         }
54     }
55 
56     unsafe impl objc::Encode for NSPoint {
encode() -> objc::Encoding57         fn encode() -> objc::Encoding {
58             let encoding = format!("{{CGPoint={}{}}}",
59                                    f64::encode().as_str(),
60                                    f64::encode().as_str());
61             unsafe { objc::Encoding::from_str(&encoding) }
62         }
63     }
64 
65     #[repr(C)]
66     #[derive(Copy, Clone)]
67     pub struct NSSize {
68         pub width: f64,
69         pub height: f64,
70     }
71 
72     impl NSSize {
73         #[inline]
new(width: f64, height: f64) -> NSSize74         pub fn new(width: f64, height: f64) -> NSSize {
75             NSSize {
76                 width: width,
77                 height: height,
78             }
79         }
80     }
81 
82     unsafe impl objc::Encode for NSSize {
encode() -> objc::Encoding83         fn encode() -> objc::Encoding {
84             let encoding = format!("{{CGSize={}{}}}",
85                                    f64::encode().as_str(),
86                                    f64::encode().as_str());
87             unsafe { objc::Encoding::from_str(&encoding) }
88         }
89     }
90 
91     #[repr(C)]
92     #[derive(Copy, Clone)]
93     pub struct NSRect {
94         pub origin: NSPoint,
95         pub size: NSSize,
96     }
97 
98     impl NSRect {
99         #[inline]
new(origin: NSPoint, size: NSSize) -> NSRect100         pub fn new(origin: NSPoint, size: NSSize) -> NSRect {
101             NSRect {
102                 origin: origin,
103                 size: size
104             }
105         }
106 
107         #[inline]
as_CGRect(&self) -> &CGRect108         pub fn as_CGRect(&self) -> &CGRect {
109             unsafe {
110                 mem::transmute::<&NSRect, &CGRect>(self)
111             }
112         }
113 
114         #[inline]
inset(&self, x: CGFloat, y: CGFloat) -> NSRect115         pub fn inset(&self, x: CGFloat, y: CGFloat) -> NSRect {
116             unsafe {
117                 NSInsetRect(*self, x, y)
118             }
119         }
120     }
121 
122     unsafe impl objc::Encode for NSRect {
encode() -> objc::Encoding123         fn encode() -> objc::Encoding {
124             let encoding = format!("{{CGRect={}{}}}",
125                                    NSPoint::encode().as_str(),
126                                    NSSize::encode().as_str());
127             unsafe { objc::Encoding::from_str(&encoding) }
128         }
129     }
130 
131     // Same as CGRectEdge
132     #[repr(u32)]
133     pub enum NSRectEdge {
134         NSRectMinXEdge,
135         NSRectMinYEdge,
136         NSRectMaxXEdge,
137         NSRectMaxYEdge,
138     }
139 
140     #[link(name = "Foundation", kind = "framework")]
141     extern {
NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect142         fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect;
143     }
144 
145     pub trait NSValue: Sized {
valueWithPoint(_: Self, point: NSPoint) -> id146         unsafe fn valueWithPoint(_: Self, point: NSPoint) -> id {
147             msg_send![class!(NSValue), valueWithPoint:point]
148         }
149 
valueWithSize(_: Self, size: NSSize) -> id150         unsafe fn valueWithSize(_: Self, size: NSSize) -> id {
151             msg_send![class!(NSValue), valueWithSize:size]
152         }
153     }
154 
155     impl NSValue for id {
156     }
157 }
158 
159 #[cfg(target_os = "macos")]
160 pub use self::macos::*;
161 
162 #[repr(C)]
163 pub struct NSRange {
164     pub location: NSUInteger,
165     pub length: NSUInteger,
166 }
167 
168 impl NSRange {
169     #[inline]
new(location: NSUInteger, length: NSUInteger) -> NSRange170     pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange {
171         NSRange {
172             location: location,
173             length: length
174         }
175     }
176 }
177 
178 #[link(name = "Foundation", kind = "framework")]
179 extern {
180     pub static NSDefaultRunLoopMode: id;
181 }
182 
183 pub trait NSAutoreleasePool: Sized {
new(_: Self) -> id184     unsafe fn new(_: Self) -> id {
185         msg_send![class!(NSAutoreleasePool), new]
186     }
187 
autorelease(self) -> Self188     unsafe fn autorelease(self) -> Self;
drain(self)189     unsafe fn drain(self);
190 }
191 
192 impl NSAutoreleasePool for id {
autorelease(self) -> id193     unsafe fn autorelease(self) -> id {
194         msg_send![self, autorelease]
195     }
196 
drain(self)197     unsafe fn drain(self) {
198         msg_send![self, drain]
199     }
200 }
201 
202 pub trait NSProcessInfo: Sized {
processInfo(_: Self) -> id203     unsafe fn processInfo(_: Self) -> id {
204         msg_send![class!(NSProcessInfo), processInfo]
205     }
206 
processName(self) -> id207     unsafe fn processName(self) -> id;
208 }
209 
210 impl NSProcessInfo for id {
processName(self) -> id211     unsafe fn processName(self) -> id {
212         msg_send![self, processName]
213     }
214 }
215 
216 pub type NSTimeInterval = libc::c_double;
217 
218 pub trait NSArray: Sized {
array(_: Self) -> id219     unsafe fn array(_: Self) -> id {
220         msg_send![class!(NSArray), array]
221     }
222 
arrayWithObjects(_: Self, objects: &[id]) -> id223     unsafe fn arrayWithObjects(_: Self, objects: &[id]) -> id {
224         msg_send![class!(NSArray), arrayWithObjects:objects.as_ptr()
225                                     count:objects.len()]
226     }
227 
arrayWithObject(_: Self, object: id) -> id228     unsafe fn arrayWithObject(_: Self, object: id) -> id {
229         msg_send![class!(NSArray), arrayWithObject:object]
230     }
231 
arrayByAddingObjectFromArray(self, object: id) -> id232     unsafe fn arrayByAddingObjectFromArray(self, object: id) -> id;
arrayByAddingObjectsFromArray(self, objects: id) -> id233     unsafe fn arrayByAddingObjectsFromArray(self, objects: id) -> id;
234 }
235 
236 impl NSArray for id {
arrayByAddingObjectFromArray(self, object: id) -> id237     unsafe fn arrayByAddingObjectFromArray(self, object: id) -> id {
238         msg_send![self, arrayByAddingObjectFromArray:object]
239     }
240 
arrayByAddingObjectsFromArray(self, objects: id) -> id241     unsafe fn arrayByAddingObjectsFromArray(self, objects: id) -> id {
242         msg_send![self, arrayByAddingObjectsFromArray:objects]
243     }
244 }
245 
246 pub trait NSDictionary: Sized {
dictionary(_: Self) -> id247     unsafe fn dictionary(_: Self) -> id {
248         msg_send![class!(NSDictionary), dictionary]
249     }
250 
dictionaryWithContentsOfFile_(_: Self, path: id) -> id251     unsafe fn dictionaryWithContentsOfFile_(_: Self, path: id) -> id {
252         msg_send![class!(NSDictionary), dictionaryWithContentsOfFile:path]
253     }
254 
dictionaryWithContentsOfURL_(_: Self, aURL: id) -> id255     unsafe fn dictionaryWithContentsOfURL_(_: Self, aURL: id) -> id {
256         msg_send![class!(NSDictionary), dictionaryWithContentsOfURL:aURL]
257     }
258 
dictionaryWithDictionary_(_: Self, otherDictionary: id) -> id259     unsafe fn dictionaryWithDictionary_(_: Self, otherDictionary: id) -> id {
260         msg_send![class!(NSDictionary), dictionaryWithDictionary:otherDictionary]
261     }
262 
dictionaryWithObject_forKey_(_: Self, anObject: id, aKey: id) -> id263     unsafe fn dictionaryWithObject_forKey_(_: Self, anObject: id, aKey: id) -> id {
264         msg_send![class!(NSDictionary), dictionaryWithObject:anObject forKey:aKey]
265     }
266 
dictionaryWithObjects_forKeys_(_: Self, objects: id, keys: id) -> id267     unsafe fn dictionaryWithObjects_forKeys_(_: Self, objects: id, keys: id) -> id {
268         msg_send![class!(NSDictionary), dictionaryWithObjects:objects forKeys:keys]
269     }
270 
dictionaryWithObjects_forKeys_count_(_: Self, objects: *const id, keys: *const id, count: NSUInteger) -> id271     unsafe fn dictionaryWithObjects_forKeys_count_(_: Self, objects: *const id, keys: *const id, count: NSUInteger) -> id {
272         msg_send![class!(NSDictionary), dictionaryWithObjects:objects forKeys:keys count:count]
273     }
274 
dictionaryWithObjectsAndKeys_(_: Self, firstObject: id) -> id275     unsafe fn dictionaryWithObjectsAndKeys_(_: Self, firstObject: id) -> id {
276         msg_send![class!(NSDictionary), dictionaryWithObjectsAndKeys:firstObject]
277     }
278 
init(self) -> id279     unsafe fn init(self) -> id;
initWithContentsOfFile_(self, path: id) -> id280     unsafe fn initWithContentsOfFile_(self, path: id) -> id;
initWithContentsOfURL_(self, aURL: id) -> id281     unsafe fn initWithContentsOfURL_(self, aURL: id) -> id;
initWithDictionary_(self, otherDicitonary: id) -> id282     unsafe fn initWithDictionary_(self, otherDicitonary: id) -> id;
initWithDictionary_copyItems_(self, otherDicitonary: id, flag: BOOL) -> id283     unsafe fn initWithDictionary_copyItems_(self, otherDicitonary: id, flag: BOOL) -> id;
initWithObjects_forKeys_(self, objects: id, keys: id) -> id284     unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id;
initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id285     unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id;
initWithObjectsAndKeys_(self, firstObject: id) -> id286     unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id;
287 
sharedKeySetForKeys_(_: Self, keys: id) -> id288     unsafe fn sharedKeySetForKeys_(_: Self, keys: id) -> id {
289         msg_send![class!(NSDictionary), sharedKeySetForKeys:keys]
290     }
291 
count(self) -> NSUInteger292     unsafe fn count(self) -> NSUInteger;
293 
isEqualToDictionary_(self, otherDictionary: id) -> BOOL294     unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL;
295 
allKeys(self) -> id296     unsafe fn allKeys(self) -> id;
allKeysForObject_(self, anObject: id) -> id297     unsafe fn allKeysForObject_(self, anObject: id) -> id;
allValues(self) -> id298     unsafe fn allValues(self) -> id;
objectForKey_(self, aKey: id) -> id299     unsafe fn objectForKey_(self, aKey: id) -> id;
objectForKeyedSubscript_(self, key: id) -> id300     unsafe fn objectForKeyedSubscript_(self, key: id) -> id;
objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id301     unsafe fn objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id;
valueForKey_(self, key: id) -> id302     unsafe fn valueForKey_(self, key: id) -> id;
303 
keyEnumerator(self) -> id304     unsafe fn keyEnumerator(self) -> id;
objectEnumerator(self) -> id305     unsafe fn objectEnumerator(self) -> id;
enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>)306     unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>);
enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions, block: *mut Block<(id, id, *mut BOOL), ()>)307     unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions,
308                                                              block: *mut Block<(id, id, *mut BOOL), ()>);
309 
keysSortedByValueUsingSelector_(self, comparator: SEL) -> id310     unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id;
keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id311     unsafe fn keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id;
keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id312     unsafe fn keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id;
313 
keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id314     unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id;
keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id315     unsafe fn keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions,
316                                                     predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id;
317 
writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL318     unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL;
writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL319     unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL;
320 
fileCreationDate(self) -> id321     unsafe fn fileCreationDate(self) -> id;
fileExtensionHidden(self) -> BOOL322     unsafe fn fileExtensionHidden(self) -> BOOL;
fileGroupOwnerAccountID(self) -> id323     unsafe fn fileGroupOwnerAccountID(self) -> id;
fileGroupOwnerAccountName(self) -> id324     unsafe fn fileGroupOwnerAccountName(self) -> id;
fileIsAppendOnly(self) -> BOOL325     unsafe fn fileIsAppendOnly(self) -> BOOL;
fileIsImmutable(self) -> BOOL326     unsafe fn fileIsImmutable(self) -> BOOL;
fileModificationDate(self) -> id327     unsafe fn fileModificationDate(self) -> id;
fileOwnerAccountID(self) -> id328     unsafe fn fileOwnerAccountID(self) -> id;
fileOwnerAccountName(self) -> id329     unsafe fn fileOwnerAccountName(self) -> id;
filePosixPermissions(self) -> NSUInteger330     unsafe fn filePosixPermissions(self) -> NSUInteger;
fileSize(self) -> libc::c_ulonglong331     unsafe fn fileSize(self) -> libc::c_ulonglong;
fileSystemFileNumber(self) -> NSUInteger332     unsafe fn fileSystemFileNumber(self) -> NSUInteger;
fileSystemNumber(self) -> NSInteger333     unsafe fn fileSystemNumber(self) -> NSInteger;
fileType(self) -> id334     unsafe fn fileType(self) -> id;
335 
description(self) -> id336     unsafe fn description(self) -> id;
descriptionInStringsFileFormat(self) -> id337     unsafe fn descriptionInStringsFileFormat(self) -> id;
descriptionWithLocale_(self, locale: id) -> id338     unsafe fn descriptionWithLocale_(self, locale: id) -> id;
descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id339     unsafe fn descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id;
340 }
341 
342 impl NSDictionary for id {
init(self) -> id343     unsafe fn init(self) -> id {
344         msg_send![self, init]
345     }
346 
initWithContentsOfFile_(self, path: id) -> id347     unsafe fn initWithContentsOfFile_(self, path: id) -> id {
348         msg_send![self, initWithContentsOfFile:path]
349     }
350 
initWithContentsOfURL_(self, aURL: id) -> id351     unsafe fn initWithContentsOfURL_(self, aURL: id) -> id {
352         msg_send![self, initWithContentsOfURL:aURL]
353     }
354 
initWithDictionary_(self, otherDictionary: id) -> id355     unsafe fn initWithDictionary_(self, otherDictionary: id) -> id {
356         msg_send![self, initWithDictionary:otherDictionary]
357     }
358 
initWithDictionary_copyItems_(self, otherDictionary: id, flag: BOOL) -> id359     unsafe fn initWithDictionary_copyItems_(self, otherDictionary: id, flag: BOOL) -> id {
360         msg_send![self, initWithDictionary:otherDictionary copyItems:flag]
361     }
362 
initWithObjects_forKeys_(self, objects: id, keys: id) -> id363     unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id {
364         msg_send![self, initWithObjects:objects forKeys:keys]
365     }
366 
initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id367     unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id {
368         msg_send![self, initWithObjects:objects forKeys:keys count:count]
369     }
370 
initWithObjectsAndKeys_(self, firstObject: id) -> id371     unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id {
372         msg_send![self, initWithObjectsAndKeys:firstObject]
373     }
374 
count(self) -> NSUInteger375     unsafe fn count(self) -> NSUInteger {
376         msg_send![self, count]
377     }
378 
isEqualToDictionary_(self, otherDictionary: id) -> BOOL379     unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL {
380         msg_send![self, isEqualToDictionary:otherDictionary]
381     }
382 
allKeys(self) -> id383     unsafe fn allKeys(self) -> id {
384         msg_send![self, allKeys]
385     }
386 
allKeysForObject_(self, anObject: id) -> id387     unsafe fn allKeysForObject_(self, anObject: id) -> id {
388         msg_send![self, allKeysForObject:anObject]
389     }
390 
allValues(self) -> id391     unsafe fn allValues(self) -> id {
392         msg_send![self, allValues]
393     }
394 
objectForKey_(self, aKey: id) -> id395     unsafe fn objectForKey_(self, aKey: id) -> id {
396         msg_send![self, objectForKey:aKey]
397     }
398 
objectForKeyedSubscript_(self, key: id) -> id399     unsafe fn objectForKeyedSubscript_(self, key: id) -> id {
400         msg_send![self, objectForKeyedSubscript:key]
401     }
402 
objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id403     unsafe fn objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id {
404         msg_send![self, objectsForKeys:keys notFoundMarker:anObject]
405     }
406 
valueForKey_(self, key: id) -> id407     unsafe fn valueForKey_(self, key: id) -> id {
408         msg_send![self, valueForKey:key]
409     }
410 
keyEnumerator(self) -> id411     unsafe fn keyEnumerator(self) -> id {
412         msg_send![self, keyEnumerator]
413     }
414 
objectEnumerator(self) -> id415     unsafe fn objectEnumerator(self) -> id {
416         msg_send![self, objectEnumerator]
417     }
418 
enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>)419     unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>) {
420         msg_send![self, enumerateKeysAndObjectsUsingBlock:block]
421     }
422 
enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions, block: *mut Block<(id, id, *mut BOOL), ()>)423     unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions,
424                                                      block: *mut Block<(id, id, *mut BOOL), ()>) {
425         msg_send![self, enumerateKeysAndObjectsWithOptions:opts usingBlock:block]
426     }
427 
keysSortedByValueUsingSelector_(self, comparator: SEL) -> id428     unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id {
429         msg_send![self, keysSortedByValueUsingSelector:comparator]
430     }
431 
keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id432     unsafe fn keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id {
433         msg_send![self, keysSortedByValueUsingComparator:cmptr]
434     }
435 
keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id436     unsafe fn keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id {
437         let rv: id = msg_send![self, keysSortedByValueWithOptions:opts usingComparator:cmptr];
438         rv
439     }
440 
keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id441     unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id {
442         msg_send![self, keysOfEntriesPassingTest:predicate]
443     }
444 
keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id445     unsafe fn keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions,
446                                                     predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id {
447         msg_send![self, keysOfEntriesWithOptions:opts PassingTest:predicate]
448     }
449 
writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL450     unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL {
451         msg_send![self, writeToFile:path atomically:flag]
452     }
453 
writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL454     unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL {
455         msg_send![self, writeToURL:aURL atomically:flag]
456     }
457 
fileCreationDate(self) -> id458     unsafe fn fileCreationDate(self) -> id {
459         msg_send![self, fileCreationDate]
460     }
461 
fileExtensionHidden(self) -> BOOL462     unsafe fn fileExtensionHidden(self) -> BOOL {
463         msg_send![self, fileExtensionHidden]
464     }
465 
fileGroupOwnerAccountID(self) -> id466     unsafe fn fileGroupOwnerAccountID(self) -> id {
467         msg_send![self, fileGroupOwnerAccountID]
468     }
469 
fileGroupOwnerAccountName(self) -> id470     unsafe fn fileGroupOwnerAccountName(self) -> id {
471         msg_send![self, fileGroupOwnerAccountName]
472     }
473 
fileIsAppendOnly(self) -> BOOL474     unsafe fn fileIsAppendOnly(self) -> BOOL {
475         msg_send![self, fileIsAppendOnly]
476     }
477 
fileIsImmutable(self) -> BOOL478     unsafe fn fileIsImmutable(self) -> BOOL {
479         msg_send![self, fileIsImmutable]
480     }
481 
fileModificationDate(self) -> id482     unsafe fn fileModificationDate(self) -> id {
483         msg_send![self, fileModificationDate]
484     }
485 
fileOwnerAccountID(self) -> id486     unsafe fn fileOwnerAccountID(self) -> id {
487         msg_send![self, fileOwnerAccountID]
488     }
489 
fileOwnerAccountName(self) -> id490     unsafe fn fileOwnerAccountName(self) -> id {
491         msg_send![self, fileOwnerAccountName]
492     }
493 
filePosixPermissions(self) -> NSUInteger494     unsafe fn filePosixPermissions(self) -> NSUInteger {
495         msg_send![self, filePosixPermissions]
496     }
497 
fileSize(self) -> libc::c_ulonglong498     unsafe fn fileSize(self) -> libc::c_ulonglong {
499         msg_send![self, fileSize]
500     }
501 
fileSystemFileNumber(self) -> NSUInteger502     unsafe fn fileSystemFileNumber(self) -> NSUInteger {
503         msg_send![self, fileSystemFileNumber]
504     }
505 
fileSystemNumber(self) -> NSInteger506     unsafe fn fileSystemNumber(self) -> NSInteger {
507         msg_send![self, fileSystemNumber]
508     }
509 
fileType(self) -> id510     unsafe fn fileType(self) -> id {
511         msg_send![self, fileType]
512     }
513 
description(self) -> id514     unsafe fn description(self) -> id {
515         msg_send![self, description]
516     }
517 
descriptionInStringsFileFormat(self) -> id518     unsafe fn descriptionInStringsFileFormat(self) -> id {
519         msg_send![self, descriptionInStringsFileFormat]
520     }
521 
descriptionWithLocale_(self, locale: id) -> id522     unsafe fn descriptionWithLocale_(self, locale: id) -> id {
523         msg_send![self, descriptionWithLocale:locale]
524     }
525 
descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id526     unsafe fn descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id {
527         msg_send![self, descriptionWithLocale:locale indent:indent]
528     }
529 }
530 
531 bitflags! {
532     pub struct NSEnumerationOptions: libc::c_ulonglong {
533         const NSEnumerationConcurrent = 1 << 0;
534         const NSEnumerationReverse = 1 << 1;
535     }
536 }
537 
538 pub type NSComparator = *mut Block<(id, id), NSComparisonResult>;
539 
540 #[repr(isize)]
541 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
542 pub enum NSComparisonResult {
543     NSOrderedAscending = -1,
544     NSOrderedSame = 0,
545     NSOrderedDescending = 1
546 }
547 
548 pub trait NSString: Sized {
alloc(_: Self) -> id549     unsafe fn alloc(_: Self) -> id {
550         msg_send![class!(NSString), alloc]
551     }
552 
stringByAppendingString_(self, other: id) -> id553     unsafe fn stringByAppendingString_(self, other: id) -> id;
init_str(self, string: &str) -> Self554     unsafe fn init_str(self, string: &str) -> Self;
UTF8String(self) -> *const libc::c_char555     unsafe fn UTF8String(self) -> *const libc::c_char;
len(self) -> usize556     unsafe fn len(self) -> usize;
isEqualToString(self, &str) -> bool557     unsafe fn isEqualToString(self, &str) -> bool;
558 }
559 
560 impl NSString for id {
isEqualToString(self, other: &str) -> bool561     unsafe fn isEqualToString(self, other: &str) -> bool {
562         let other = NSString::alloc(nil).init_str(other);
563         let rv: BOOL = msg_send![self, isEqualToString:other];
564         rv != NO
565     }
566 
stringByAppendingString_(self, other: id) -> id567     unsafe fn stringByAppendingString_(self, other: id) -> id {
568         msg_send![self, stringByAppendingString:other]
569     }
570 
init_str(self, string: &str) -> id571     unsafe fn init_str(self, string: &str) -> id {
572         return msg_send![self,
573                          initWithBytes:string.as_ptr()
574                              length:string.len()
575                              encoding:UTF8_ENCODING as id];
576     }
577 
len(self) -> usize578     unsafe fn len(self) -> usize {
579         msg_send![self, lengthOfBytesUsingEncoding:UTF8_ENCODING]
580     }
581 
UTF8String(self) -> *const libc::c_char582     unsafe fn UTF8String(self) -> *const libc::c_char {
583         msg_send![self, UTF8String]
584     }
585 }
586 
587 pub trait NSDate: Sized {
distantPast(_: Self) -> id588     unsafe fn distantPast(_: Self) -> id {
589         msg_send![class!(NSDate), distantPast]
590     }
591 
distantFuture(_: Self) -> id592     unsafe fn distantFuture(_: Self) -> id {
593         msg_send![class!(NSDate), distantFuture]
594     }
595 }
596 
597 impl NSDate for id {
598 
599 }
600 
601 #[repr(C)]
602 struct NSFastEnumerationState {
603     pub state: libc::c_ulong,
604     pub items_ptr: *mut id,
605     pub mutations_ptr: *mut libc::c_ulong,
606     pub extra: [libc::c_ulong; 5]
607 }
608 
609 const NS_FAST_ENUM_BUF_SIZE: usize = 16;
610 
611 pub struct NSFastIterator {
612     state: NSFastEnumerationState,
613     buffer: [id; NS_FAST_ENUM_BUF_SIZE],
614     mut_val: Option<libc::c_ulong>,
615     len: usize,
616     idx: usize,
617     object: id
618 }
619 
620 impl Iterator for NSFastIterator {
621     type Item = id;
622 
next(&mut self) -> Option<id>623     fn next(&mut self) -> Option<id> {
624         if self.idx >= self.len {
625             self.len = unsafe {
626                 msg_send![self.object, countByEnumeratingWithState:&mut self.state objects:self.buffer.as_mut_ptr() count:NS_FAST_ENUM_BUF_SIZE]
627             };
628             self.idx = 0;
629         }
630 
631         let new_mut = unsafe {
632             *self.state.mutations_ptr
633         };
634 
635         if let Some(old_mut) = self.mut_val {
636             assert!(old_mut == new_mut, "The collection was mutated while being enumerated");
637         }
638 
639         if self.idx < self.len {
640             let object = unsafe {
641                 *self.state.items_ptr.offset(self.idx as isize)
642             };
643             self.mut_val = Some(new_mut);
644             self.idx += 1;
645             Some(object)
646         } else {
647             None
648         }
649     }
650 }
651 
652 pub trait NSFastEnumeration: Sized {
iter(self) -> NSFastIterator653     unsafe fn iter(self) -> NSFastIterator;
654 }
655 
656 impl NSFastEnumeration for id {
iter(self) -> NSFastIterator657     unsafe fn iter(self) -> NSFastIterator {
658         NSFastIterator {
659             state: NSFastEnumerationState {
660                 state: 0,
661                 items_ptr: ptr::null_mut(),
662                 mutations_ptr: ptr::null_mut(),
663                 extra: [0; 5]
664             },
665             buffer: [nil; NS_FAST_ENUM_BUF_SIZE],
666             mut_val: None,
667             len: 0,
668             idx: 0,
669             object: self
670         }
671     }
672 }
673 
674 pub trait NSRunLoop: Sized {
currentRunLoop() -> Self675     unsafe fn currentRunLoop() -> Self;
676 
performSelector_target_argument_order_modes_(self, aSelector: SEL, target: id, anArgument: id, order: NSUInteger, modes: id)677     unsafe fn performSelector_target_argument_order_modes_(self,
678                                                            aSelector: SEL,
679                                                            target: id,
680                                                            anArgument: id,
681                                                            order: NSUInteger,
682                                                            modes: id);
683 }
684 
685 impl NSRunLoop for id {
currentRunLoop() -> id686     unsafe fn currentRunLoop() -> id {
687         msg_send![class!(NSRunLoop), currentRunLoop]
688     }
689 
performSelector_target_argument_order_modes_(self, aSelector: SEL, target: id, anArgument: id, order: NSUInteger, modes: id)690     unsafe fn performSelector_target_argument_order_modes_(self,
691                                                            aSelector: SEL,
692                                                            target: id,
693                                                            anArgument: id,
694                                                            order: NSUInteger,
695                                                            modes: id) {
696         msg_send![self, performSelector:aSelector
697                                  target:target
698                                argument:anArgument
699                                   order:order
700                                   modes:modes]
701     }
702 }
703 
704 pub trait NSData: Sized {
data(_: Self) -> id705     unsafe fn data(_: Self) -> id {
706         msg_send![class!(NSData), data]
707     }
708 
dataWithBytes_length_(_: Self, bytes: *const c_void, length: NSUInteger) -> id709     unsafe fn dataWithBytes_length_(_: Self, bytes: *const c_void, length: NSUInteger) -> id {
710         msg_send![class!(NSData), dataWithBytes:bytes length:length]
711     }
712 
dataWithBytesNoCopy_length_(_: Self, bytes: *const c_void, length: NSUInteger) -> id713     unsafe fn dataWithBytesNoCopy_length_(_: Self, bytes: *const c_void, length: NSUInteger) -> id {
714         msg_send![class!(NSData), dataWithBytesNoCopy:bytes length:length]
715     }
716 
dataWithBytesNoCopy_length_freeWhenDone_(_: Self, bytes: *const c_void, length: NSUInteger, freeWhenDone: BOOL) -> id717     unsafe fn dataWithBytesNoCopy_length_freeWhenDone_(_: Self, bytes: *const c_void,
718                                                       length: NSUInteger, freeWhenDone: BOOL) -> id {
719         msg_send![class!(NSData), dataWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone]
720     }
721 
dataWithContentsOfFile_(_: Self, path: id) -> id722     unsafe fn dataWithContentsOfFile_(_: Self, path: id) -> id {
723         msg_send![class!(NSData), dataWithContentsOfFile:path]
724     }
725 
dataWithContentsOfFile_options_error_(_: Self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id726     unsafe fn dataWithContentsOfFile_options_error_(_: Self, path: id, mask: NSDataReadingOptions,
727                                                     errorPtr: *mut id) -> id {
728         msg_send![class!(NSData), dataWithContentsOfFile:path options:mask error:errorPtr]
729     }
730 
dataWithContentsOfURL_(_: Self, aURL: id) -> id731     unsafe fn dataWithContentsOfURL_(_: Self, aURL: id) -> id {
732         msg_send![class!(NSData), dataWithContentsOfURL:aURL]
733     }
734 
dataWithContentsOfURL_options_error_(_: Self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id735     unsafe fn dataWithContentsOfURL_options_error_(_: Self, aURL: id, mask: NSDataReadingOptions,
736                                                    errorPtr: *mut id) -> id {
737         msg_send![class!(NSData), dataWithContentsOfURL:aURL options:mask error:errorPtr]
738     }
739 
dataWithData_(_: Self, aData: id) -> id740     unsafe fn dataWithData_(_: Self, aData: id) -> id {
741         msg_send![class!(NSData), dataWithData:aData]
742     }
743 
initWithBase64EncodedData_options_(self, base64Data: id, options: NSDataBase64DecodingOptions) -> id744     unsafe fn initWithBase64EncodedData_options_(self, base64Data: id, options: NSDataBase64DecodingOptions)
745                                                  -> id;
initWithBase64EncodedString_options_(self, base64String: id, options: NSDataBase64DecodingOptions) -> id746     unsafe fn initWithBase64EncodedString_options_(self, base64String: id, options: NSDataBase64DecodingOptions)
747                                                    -> id;
initWithBytes_length_(self, bytes: *const c_void, length: NSUInteger) -> id748     unsafe fn initWithBytes_length_(self, bytes: *const c_void, length: NSUInteger) -> id;
initWithBytesNoCopy_length_(self, bytes: *const c_void, length: NSUInteger) -> id749     unsafe fn initWithBytesNoCopy_length_(self, bytes: *const c_void, length: NSUInteger) -> id;
initWithBytesNoCopy_length_deallocator_(self, bytes: *const c_void, length: NSUInteger, deallocator: *mut Block<(*const c_void, NSUInteger), ()>) -> id750     unsafe fn initWithBytesNoCopy_length_deallocator_(self, bytes: *const c_void, length: NSUInteger,
751                                                       deallocator: *mut Block<(*const c_void, NSUInteger), ()>)
752                                                       -> id;
initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const c_void, length: NSUInteger, freeWhenDone: BOOL) -> id753     unsafe fn initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const c_void,
754                                                        length: NSUInteger, freeWhenDone: BOOL) -> id;
initWithContentsOfFile_(self, path: id) -> id755     unsafe fn initWithContentsOfFile_(self, path: id) -> id;
initWithContentsOfFile_options_error(self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id756     unsafe fn initWithContentsOfFile_options_error(self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id)
757                                                    -> id;
initWithContentsOfURL_(self, aURL: id) -> id758     unsafe fn initWithContentsOfURL_(self, aURL: id) -> id;
initWithContentsOfURL_options_error_(self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id759     unsafe fn initWithContentsOfURL_options_error_(self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id)
760                                                    -> id;
initWithData_(self, data: id) -> id761     unsafe fn initWithData_(self, data: id) -> id;
762 
bytes(self) -> *const c_void763     unsafe fn bytes(self) -> *const c_void;
description(self) -> id764     unsafe fn description(self) -> id;
enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const c_void, NSRange, *mut BOOL), ()>)765     unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const c_void, NSRange, *mut BOOL), ()>);
getBytes_length_(self, buffer: *mut c_void, length: NSUInteger)766     unsafe fn getBytes_length_(self, buffer: *mut c_void, length: NSUInteger);
getBytes_range_(self, buffer: *mut c_void, range: NSRange)767     unsafe fn getBytes_range_(self, buffer: *mut c_void, range: NSRange);
subdataWithRange_(self, range: NSRange) -> id768     unsafe fn subdataWithRange_(self, range: NSRange) -> id;
rangeOfData_options_range_(self, dataToFind: id, options: NSDataSearchOptions, searchRange: NSRange) -> NSRange769     unsafe fn rangeOfData_options_range_(self, dataToFind: id, options: NSDataSearchOptions, searchRange: NSRange)
770                                          -> NSRange;
771 
base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id772     unsafe fn base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id;
base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id773     unsafe fn base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id;
774 
isEqualToData_(self, otherData: id) -> id775     unsafe fn isEqualToData_(self, otherData: id) -> id;
length(self) -> NSUInteger776     unsafe fn length(self) -> NSUInteger;
777 
writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL778     unsafe fn writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL;
writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL779     unsafe fn writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL;
writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL780     unsafe fn writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL;
writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL781     unsafe fn writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL;
782 }
783 
784 impl NSData for id {
initWithBase64EncodedData_options_(self, base64Data: id, options: NSDataBase64DecodingOptions) -> id785     unsafe fn initWithBase64EncodedData_options_(self, base64Data: id, options: NSDataBase64DecodingOptions)
786                                                  -> id {
787         msg_send![self, initWithBase64EncodedData:base64Data options:options]
788     }
789 
initWithBase64EncodedString_options_(self, base64String: id, options: NSDataBase64DecodingOptions) -> id790     unsafe fn initWithBase64EncodedString_options_(self, base64String: id, options: NSDataBase64DecodingOptions)
791                                                    -> id {
792         msg_send![self, initWithBase64EncodedString:base64String options:options]
793     }
794 
initWithBytes_length_(self, bytes: *const c_void, length: NSUInteger) -> id795     unsafe fn initWithBytes_length_(self, bytes: *const c_void, length: NSUInteger) -> id {
796         msg_send![self,initWithBytes:bytes length:length]
797     }
798 
initWithBytesNoCopy_length_(self, bytes: *const c_void, length: NSUInteger) -> id799     unsafe fn initWithBytesNoCopy_length_(self, bytes: *const c_void, length: NSUInteger) -> id {
800         msg_send![self, initWithBytesNoCopy:bytes length:length]
801     }
802 
initWithBytesNoCopy_length_deallocator_(self, bytes: *const c_void, length: NSUInteger, deallocator: *mut Block<(*const c_void, NSUInteger), ()>) -> id803     unsafe fn initWithBytesNoCopy_length_deallocator_(self, bytes: *const c_void, length: NSUInteger,
804                                                       deallocator: *mut Block<(*const c_void, NSUInteger), ()>)
805                                                       -> id {
806         msg_send![self, initWithBytesNoCopy:bytes length:length deallocator:deallocator]
807     }
808 
initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const c_void, length: NSUInteger, freeWhenDone: BOOL) -> id809     unsafe fn initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const c_void,
810                                                        length: NSUInteger, freeWhenDone: BOOL) -> id {
811         msg_send![self, initWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone]
812     }
813 
initWithContentsOfFile_(self, path: id) -> id814     unsafe fn initWithContentsOfFile_(self, path: id) -> id {
815         msg_send![self, initWithContentsOfFile:path]
816     }
817 
initWithContentsOfFile_options_error(self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id818     unsafe fn initWithContentsOfFile_options_error(self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id)
819                                                    -> id {
820         msg_send![self, initWithContentsOfFile:path options:mask error:errorPtr]
821     }
822 
initWithContentsOfURL_(self, aURL: id) -> id823     unsafe fn initWithContentsOfURL_(self, aURL: id) -> id {
824         msg_send![self, initWithContentsOfURL:aURL]
825     }
826 
initWithContentsOfURL_options_error_(self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id827     unsafe fn initWithContentsOfURL_options_error_(self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id)
828                                                    -> id {
829         msg_send![self, initWithContentsOfURL:aURL options:mask error:errorPtr]
830     }
831 
initWithData_(self, data: id) -> id832     unsafe fn initWithData_(self, data: id) -> id {
833         msg_send![self, initWithData:data]
834     }
835 
bytes(self) -> *const c_void836     unsafe fn bytes(self) -> *const c_void {
837         msg_send![self, bytes]
838     }
839 
description(self) -> id840     unsafe fn description(self) -> id {
841         msg_send![self, description]
842     }
843 
enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const c_void, NSRange, *mut BOOL), ()>)844     unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const c_void, NSRange, *mut BOOL), ()>) {
845         msg_send![self, enumerateByteRangesUsingBlock:block]
846     }
847 
getBytes_length_(self, buffer: *mut c_void, length: NSUInteger)848     unsafe fn getBytes_length_(self, buffer: *mut c_void, length: NSUInteger) {
849         msg_send![self, getBytes:buffer length:length]
850     }
851 
getBytes_range_(self, buffer: *mut c_void, range: NSRange)852     unsafe fn getBytes_range_(self, buffer: *mut c_void, range: NSRange) {
853         msg_send![self, getBytes:buffer range:range]
854     }
855 
subdataWithRange_(self, range: NSRange) -> id856     unsafe fn subdataWithRange_(self, range: NSRange) -> id {
857         msg_send![self, subdataWithRange:range]
858     }
859 
rangeOfData_options_range_(self, dataToFind: id, options: NSDataSearchOptions, searchRange: NSRange) -> NSRange860     unsafe fn rangeOfData_options_range_(self, dataToFind: id, options: NSDataSearchOptions, searchRange: NSRange)
861                                          -> NSRange {
862         msg_send![self, rangeOfData:dataToFind options:options range:searchRange]
863     }
864 
base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id865     unsafe fn base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id {
866         msg_send![self, base64EncodedDataWithOptions:options]
867     }
868 
base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id869     unsafe fn base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id {
870         msg_send![self, base64EncodedStringWithOptions:options]
871     }
872 
isEqualToData_(self, otherData: id) -> id873     unsafe fn isEqualToData_(self, otherData: id) -> id {
874         msg_send![self, isEqualToData:otherData]
875     }
876 
length(self) -> NSUInteger877     unsafe fn length(self) -> NSUInteger {
878         msg_send![self, length]
879     }
880 
writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL881     unsafe fn writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL {
882         msg_send![self, writeToFile:path atomically:atomically]
883     }
884 
writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL885     unsafe fn writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL {
886         msg_send![self, writeToFile:path options:mask error:errorPtr]
887     }
888 
writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL889     unsafe fn writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL {
890         msg_send![self, writeToURL:aURL atomically:atomically]
891     }
892 
writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL893     unsafe fn writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL {
894         msg_send![self, writeToURL:aURL options:mask error:errorPtr]
895     }
896 }
897 
898 bitflags! {
899     pub struct NSDataReadingOptions: libc::c_ulonglong {
900        const NSDataReadingMappedIfSafe = 1 << 0;
901        const NSDataReadingUncached = 1 << 1;
902        const NSDataReadingMappedAlways = 1 << 3;
903     }
904 }
905 
906 bitflags! {
907     pub struct NSDataBase64EncodingOptions: libc::c_ulonglong {
908         const NSDataBase64Encoding64CharacterLineLength = 1 << 0;
909         const NSDataBase64Encoding76CharacterLineLength = 1 << 1;
910         const NSDataBase64EncodingEndLineWithCarriageReturn = 1 << 4;
911         const NSDataBase64EncodingEndLineWithLineFeed = 1 << 5;
912     }
913 }
914 
915 bitflags! {
916     pub struct NSDataBase64DecodingOptions: libc::c_ulonglong {
917        const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0;
918     }
919 }
920 
921 bitflags! {
922     pub struct NSDataWritingOptions: libc::c_ulonglong {
923         const NSDataWritingAtomic = 1 << 0;
924         const NSDataWritingWithoutOverwriting = 1 << 1;
925     }
926 }
927 
928 bitflags! {
929     pub struct NSDataSearchOptions: libc::c_ulonglong {
930         const NSDataSearchBackwards = 1 << 0;
931         const NSDataSearchAnchored = 1 << 1;
932     }
933 }
934