@@ -14,6 +14,7 @@ use std::os::raw::c_void;
1414use base:: { id, BOOL , NO , SEL , nil} ;
1515use block:: Block ;
1616use libc;
17+ use objc_encode:: { Encode , Encoding } ;
1718
1819
1920#[ cfg( target_pointer_width = "32" ) ]
@@ -37,7 +38,7 @@ mod macos {
3738 use base:: id;
3839 use core_graphics_types:: base:: CGFloat ;
3940 use core_graphics_types:: geometry:: CGRect ;
40- use objc ;
41+ use objc_encode :: { Encode , Encoding } ;
4142
4243 #[ repr( C ) ]
4344 #[ derive( Copy , Clone ) ]
@@ -56,13 +57,9 @@ mod macos {
5657 }
5758 }
5859
59- unsafe impl objc:: Encode for NSPoint {
60- fn encode ( ) -> objc:: Encoding {
61- let encoding = format ! ( "{{CGPoint={}{}}}" ,
62- CGFloat :: encode( ) . as_str( ) ,
63- CGFloat :: encode( ) . as_str( ) ) ;
64- unsafe { objc:: Encoding :: from_str ( & encoding) }
65- }
60+ unsafe impl Encode for NSPoint {
61+ const ENCODING : Encoding < ' static > =
62+ Encoding :: Struct ( "CGPoint" , & [ CGFloat :: ENCODING , CGFloat :: ENCODING ] ) ;
6663 }
6764
6865 #[ repr( C ) ]
@@ -82,13 +79,9 @@ mod macos {
8279 }
8380 }
8481
85- unsafe impl objc:: Encode for NSSize {
86- fn encode ( ) -> objc:: Encoding {
87- let encoding = format ! ( "{{CGSize={}{}}}" ,
88- CGFloat :: encode( ) . as_str( ) ,
89- CGFloat :: encode( ) . as_str( ) ) ;
90- unsafe { objc:: Encoding :: from_str ( & encoding) }
91- }
82+ unsafe impl Encode for NSSize {
83+ const ENCODING : Encoding < ' static > =
84+ Encoding :: Struct ( "CGSize" , & [ CGFloat :: ENCODING , CGFloat :: ENCODING ] ) ;
9285 }
9386
9487 #[ repr( C ) ]
@@ -122,13 +115,9 @@ mod macos {
122115 }
123116 }
124117
125- unsafe impl objc:: Encode for NSRect {
126- fn encode ( ) -> objc:: Encoding {
127- let encoding = format ! ( "{{CGRect={}{}}}" ,
128- NSPoint :: encode( ) . as_str( ) ,
129- NSSize :: encode( ) . as_str( ) ) ;
130- unsafe { objc:: Encoding :: from_str ( & encoding) }
131- }
118+ unsafe impl Encode for NSRect {
119+ const ENCODING : Encoding < ' static > =
120+ Encoding :: Struct ( "CGRect" , & [ NSPoint :: ENCODING , NSSize :: ENCODING ] ) ;
132121 }
133122
134123 // Same as CGRectEdge
@@ -140,6 +129,8 @@ mod macos {
140129 NSRectMaxYEdge ,
141130 }
142131
132+ impl_Encode ! ( NSRectEdge , u32 ) ;
133+
143134 #[ link( name = "Foundation" , kind = "framework" ) ]
144135 extern {
145136 fn NSInsetRect ( rect : NSRect , x : CGFloat , y : CGFloat ) -> NSRect ;
@@ -169,6 +160,11 @@ pub struct NSRange {
169160 pub length : NSUInteger ,
170161}
171162
163+ unsafe impl Encode for NSRange {
164+ const ENCODING : Encoding < ' static > =
165+ Encoding :: Struct ( "_NSRange" , & [ NSUInteger :: ENCODING , NSUInteger :: ENCODING ] ) ;
166+ }
167+
172168impl NSRange {
173169 #[ inline]
174170 pub fn new ( location : NSUInteger , length : NSUInteger ) -> NSRange {
@@ -212,6 +208,17 @@ pub struct NSOperatingSystemVersion {
212208 pub patchVersion : NSUInteger ,
213209}
214210
211+ unsafe impl Encode for NSOperatingSystemVersion {
212+ const ENCODING : Encoding < ' static > = Encoding :: Struct (
213+ "NSOperatingSystemVersion" ,
214+ & [
215+ NSUInteger :: ENCODING ,
216+ NSUInteger :: ENCODING ,
217+ NSUInteger :: ENCODING ,
218+ ] ,
219+ ) ;
220+ }
221+
215222impl NSOperatingSystemVersion {
216223 #[ inline]
217224 pub fn new ( majorVersion : NSUInteger , minorVersion : NSUInteger , patchVersion : NSUInteger ) -> NSOperatingSystemVersion {
@@ -593,6 +600,8 @@ bitflags! {
593600 }
594601}
595602
603+ impl_Encode ! ( NSEnumerationOptions , libc:: c_ulonglong) ;
604+
596605pub type NSComparator = * mut Block < ( id , id ) , NSComparisonResult > ;
597606
598607#[ repr( isize ) ]
@@ -603,6 +612,8 @@ pub enum NSComparisonResult {
603612 NSOrderedDescending = 1
604613}
605614
615+ impl_Encode ! ( NSComparisonResult , isize ) ;
616+
606617pub trait NSString : Sized {
607618 unsafe fn alloc ( _: Self ) -> id {
608619 msg_send ! [ class!( NSString ) , alloc]
@@ -669,6 +680,23 @@ struct NSFastEnumerationState {
669680 pub extra : [ libc:: c_ulong ; 5 ]
670681}
671682
683+ unsafe impl Encode for NSFastEnumerationState {
684+ const ENCODING : Encoding < ' static > = Encoding :: Struct (
685+ "?" ,
686+ & [
687+ libc:: c_ulong:: ENCODING ,
688+ Encoding :: Pointer ( & Encoding :: Object ) ,
689+ Encoding :: Pointer ( & libc:: c_ulong:: ENCODING ) ,
690+ Encoding :: Array ( 5 , & libc:: c_ulong:: ENCODING ) ,
691+ ] ,
692+ ) ;
693+ }
694+
695+ unsafe impl Encode for & ' _ NSFastEnumerationState {
696+ const ENCODING : Encoding < ' static > =
697+ Encoding :: Pointer ( & NSFastEnumerationState :: ENCODING ) ;
698+ }
699+
672700const NS_FAST_ENUM_BUF_SIZE : usize = 16 ;
673701
674702pub struct NSFastIterator {
@@ -677,7 +705,7 @@ pub struct NSFastIterator {
677705 mut_val : Option < libc:: c_ulong > ,
678706 len : usize ,
679707 idx : usize ,
680- object : id
708+ object : id ,
681709}
682710
683711impl Iterator for NSFastIterator {
@@ -774,6 +802,8 @@ bitflags! {
774802 }
775803}
776804
805+ impl_Encode ! ( NSURLBookmarkCreationOptions , NSUInteger ) ;
806+
777807pub type NSURLBookmarkFileCreationOptions = NSURLBookmarkCreationOptions ;
778808
779809bitflags ! {
@@ -784,6 +814,7 @@ bitflags! {
784814 }
785815}
786816
817+ impl_Encode ! ( NSURLBookmarkResolutionOptions , NSUInteger ) ;
787818
788819pub trait NSURL : Sized {
789820 unsafe fn alloc ( _: Self ) -> id ;
@@ -1337,6 +1368,8 @@ bitflags! {
13371368 }
13381369}
13391370
1371+ impl_Encode ! ( NSDataReadingOptions , libc:: c_ulonglong) ;
1372+
13401373bitflags ! {
13411374 pub struct NSDataBase64EncodingOptions : libc:: c_ulonglong {
13421375 const NSDataBase64Encoding64CharacterLineLength = 1 << 0 ;
@@ -1346,26 +1379,34 @@ bitflags! {
13461379 }
13471380}
13481381
1382+ impl_Encode ! ( NSDataBase64EncodingOptions , libc:: c_ulonglong) ;
1383+
13491384bitflags ! {
13501385 pub struct NSDataBase64DecodingOptions : libc:: c_ulonglong {
13511386 const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0 ;
13521387 }
13531388}
13541389
1390+ impl_Encode ! ( NSDataBase64DecodingOptions , libc:: c_ulonglong) ;
1391+
13551392bitflags ! {
13561393 pub struct NSDataWritingOptions : libc:: c_ulonglong {
13571394 const NSDataWritingAtomic = 1 << 0 ;
13581395 const NSDataWritingWithoutOverwriting = 1 << 1 ;
13591396 }
13601397}
13611398
1399+ impl_Encode ! ( NSDataWritingOptions , libc:: c_ulonglong) ;
1400+
13621401bitflags ! {
13631402 pub struct NSDataSearchOptions : libc:: c_ulonglong {
13641403 const NSDataSearchBackwards = 1 << 0 ;
13651404 const NSDataSearchAnchored = 1 << 1 ;
13661405 }
13671406}
13681407
1408+ impl_Encode ! ( NSDataSearchOptions , libc:: c_ulonglong) ;
1409+
13691410pub trait NSUserDefaults {
13701411 unsafe fn standardUserDefaults ( ) -> Self ;
13711412
0 commit comments