@@ -19,60 +19,52 @@ unsafe impl Send for NSData {}
19
19
impl UnwindSafe for NSData { }
20
20
impl RefUnwindSafe for NSData { }
21
21
22
- extern_methods ! (
23
- /// Creation methods.
24
- unsafe impl NSData {
25
- #[ method_id( new) ]
26
- pub fn new( ) -> Id <Self >;
27
-
28
- pub fn with_bytes( bytes: & [ u8 ] ) -> Id <Self > {
29
- let bytes_ptr = bytes. as_ptr( ) as * mut c_void;
30
- unsafe { Self :: initWithBytes_length( Self :: alloc( ) , bytes_ptr, bytes. len( ) ) }
31
- }
22
+ /// Creation methods.
23
+ impl NSData {
24
+ pub fn with_bytes ( bytes : & [ u8 ] ) -> Id < Self > {
25
+ let bytes_ptr = bytes. as_ptr ( ) as * mut c_void ;
26
+ unsafe { Self :: initWithBytes_length ( Self :: alloc ( ) , bytes_ptr, bytes. len ( ) ) }
27
+ }
32
28
33
- #[ cfg( feature = "block" ) ]
34
- pub fn from_vec( bytes: Vec <u8 >) -> Id <Self > {
35
- // GNUStep's NSData `initWithBytesNoCopy:length:deallocator:` has a
36
- // bug; it forgets to assign the input buffer and length to the
37
- // instance before it swizzles to NSDataWithDeallocatorBlock.
38
- // See https://github.com/gnustep/libs-base/pull/213
39
- // So we just use NSDataWithDeallocatorBlock directly.
40
- //
41
- // NSMutableData does not have this problem.
42
- #[ cfg( feature = "gnustep-1-7" ) ]
43
- let cls = objc2:: class!( NSDataWithDeallocatorBlock ) ;
44
- #[ cfg( not( feature = "gnustep-1-7" ) ) ]
45
- let cls = Self :: class( ) ;
46
-
47
- unsafe { Id :: cast( with_vec( cls, bytes) ) }
48
- }
29
+ #[ cfg( feature = "block" ) ]
30
+ pub fn from_vec ( bytes : Vec < u8 > ) -> Id < Self > {
31
+ // GNUStep's NSData `initWithBytesNoCopy:length:deallocator:` has a
32
+ // bug; it forgets to assign the input buffer and length to the
33
+ // instance before it swizzles to NSDataWithDeallocatorBlock.
34
+ // See https://github.com/gnustep/libs-base/pull/213
35
+ // So we just use NSDataWithDeallocatorBlock directly.
36
+ //
37
+ // NSMutableData does not have this problem.
38
+ #[ cfg( feature = "gnustep-1-7" ) ]
39
+ let cls = objc2:: class!( NSDataWithDeallocatorBlock ) ;
40
+ #[ cfg( not( feature = "gnustep-1-7" ) ) ]
41
+ let cls = Self :: class ( ) ;
42
+
43
+ unsafe { Id :: cast ( with_vec ( cls, bytes) ) }
49
44
}
45
+ }
50
46
51
- /// Accessor methods.
52
- unsafe impl NSData {
53
- pub fn len( & self ) -> usize {
54
- self . length( )
55
- }
47
+ /// Accessor methods.
48
+ impl NSData {
49
+ pub fn len ( & self ) -> usize {
50
+ self . length ( )
51
+ }
56
52
57
- pub fn is_empty( & self ) -> bool {
58
- self . len( ) == 0
59
- }
53
+ pub fn is_empty ( & self ) -> bool {
54
+ self . len ( ) == 0
55
+ }
60
56
61
- #[ method( bytes) ]
62
- fn bytes_raw( & self ) -> * const c_void;
63
-
64
- pub fn bytes( & self ) -> & [ u8 ] {
65
- let ptr = self . bytes_raw( ) ;
66
- let ptr: * const u8 = ptr. cast( ) ;
67
- // The bytes pointer may be null for length zero
68
- if ptr. is_null( ) {
69
- & [ ]
70
- } else {
71
- unsafe { slice:: from_raw_parts( ptr, self . len( ) ) }
72
- }
57
+ pub fn bytes ( & self ) -> & [ u8 ] {
58
+ let ptr = self . bytes_raw ( ) ;
59
+ let ptr: * const u8 = ptr. cast ( ) ;
60
+ // The bytes pointer may be null for length zero
61
+ if ptr. is_null ( ) {
62
+ & [ ]
63
+ } else {
64
+ unsafe { slice:: from_raw_parts ( ptr, self . len ( ) ) }
73
65
}
74
66
}
75
- ) ;
67
+ }
76
68
77
69
impl AsRef < [ u8 ] > for NSData {
78
70
fn as_ref ( & self ) -> & [ u8 ] {
0 commit comments