13
13
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
14
14
//
15
15
16
- /// Implements array accessing methods for a type that must be considered safe
16
+ /// Implements newtype wrapping methods
17
17
#[ macro_export]
18
- macro_rules! impl_safe_array_newtype {
19
- ( $thing: ident, $ty: ty, $len : expr ) => {
18
+ macro_rules! impl_ptr_newtype {
19
+ ( $thing: ident, $ty: ty) => {
20
20
impl $thing {
21
21
#[ inline]
22
22
#[ allow( unused) ]
@@ -33,35 +33,19 @@ macro_rules! impl_safe_array_newtype {
33
33
let & mut $thing( ref mut dat) = self ;
34
34
dat. as_mut_ptr( )
35
35
}
36
-
37
- #[ inline]
38
- /// Returns the length of the object as an array
39
- pub fn len( & self ) -> usize { $len }
40
-
41
- #[ inline]
42
- /// Returns whether the object as an array is empty
43
- pub fn is_empty( & self ) -> bool { false }
44
36
}
45
37
46
38
impl $crate:: CPtr for $thing {
47
39
type Target = $ty;
48
40
49
41
fn as_c_ptr( & self ) -> * const Self :: Target {
50
- if self . is_empty( ) {
51
- :: core:: ptr:: null( )
52
- } else {
53
- let & $thing( ref dat) = self ;
54
- dat. as_ptr( )
55
- }
42
+ let & $thing( ref dat) = self ;
43
+ dat. as_ptr( )
56
44
}
57
45
58
46
fn as_mut_c_ptr( & mut self ) -> * mut Self :: Target {
59
- if self . is_empty( ) {
60
- :: core:: ptr:: null:: <Self :: Target >( ) as * mut _
61
- } else {
62
- let & mut $thing( ref mut dat) = self ;
63
- dat. as_mut_ptr( )
64
- }
47
+ let & mut $thing( ref mut dat) = self ;
48
+ dat. as_mut_ptr( )
65
49
}
66
50
}
67
51
}
@@ -72,7 +56,17 @@ macro_rules! impl_safe_array_newtype {
72
56
#[ macro_export]
73
57
macro_rules! impl_array_newtype {
74
58
( $thing: ident, $ty: ty, $len: expr) => {
75
- impl_safe_array_newtype!( $thing, $ty, $len) ;
59
+ impl_ptr_newtype!( $thing, $ty) ;
60
+
61
+ impl $thing {
62
+ #[ inline]
63
+ /// Returns the length of the object as an array
64
+ pub fn len( & self ) -> usize { $len }
65
+
66
+ #[ inline]
67
+ /// Returns whether the object as an array is empty
68
+ pub fn is_empty( & self ) -> bool { false }
69
+ }
76
70
77
71
impl Copy for $thing { }
78
72
0 commit comments