1313// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1414//
1515
16- /// Implements array accessing methods for a type that must be considered safe
16+ /// Implements newtype wrapping methods
1717#[ 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) => {
2020 impl $thing {
2121 #[ inline]
2222 #[ allow( unused) ]
@@ -33,35 +33,19 @@ macro_rules! impl_safe_array_newtype {
3333 let & mut $thing( ref mut dat) = self ;
3434 dat. as_mut_ptr( )
3535 }
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 }
4436 }
4537
4638 impl $crate:: CPtr for $thing {
4739 type Target = $ty;
4840
4941 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( )
5644 }
5745
5846 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( )
6549 }
6650 }
6751 }
@@ -72,7 +56,17 @@ macro_rules! impl_safe_array_newtype {
7256#[ macro_export]
7357macro_rules! impl_array_newtype {
7458 ( $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+ }
7670
7771 impl Copy for $thing { }
7872
0 commit comments