@@ -89,8 +89,10 @@ macro_rules! closure (
89
89
/// // will use &[u8] as input type (use this if the compiler
90
90
/// // complains about lifetime issues
91
91
/// named!(my_function<&[u8]>, tag!("abcd"));
92
- /// //prefix them with 'pub' to make the functions public
92
+ /// // prefix them with 'pub' to make the functions public
93
93
/// named!(pub my_function, tag!("abcd"));
94
+ /// // prefix them with 'pub(crate)' to make the functions public within the crate
95
+ /// named!(pub(crate) my_function, tag!("abcd"));
94
96
/// ```
95
97
#[ macro_export]
96
98
macro_rules! named (
@@ -157,6 +159,36 @@ macro_rules! named (
157
159
$submac!( i, $( $args) * )
158
160
}
159
161
) ;
162
+ ( pub ( crate ) $name: ident( $i: ty ) -> $o: ty, $submac: ident!( $( $args: tt) * ) ) => (
163
+ #[ allow( unused_variables) ]
164
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, u32 > {
165
+ $submac!( i, $( $args) * )
166
+ }
167
+ ) ;
168
+ ( pub ( crate ) $name: ident<$i: ty, $o: ty, $e: ty>, $submac: ident!( $( $args: tt) * ) ) => (
169
+ #[ allow( unused_variables) ]
170
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, $e> {
171
+ $submac!( i, $( $args) * )
172
+ }
173
+ ) ;
174
+ ( pub ( crate ) $name: ident<$i: ty, $o: ty>, $submac: ident!( $( $args: tt) * ) ) => (
175
+ #[ allow( unused_variables) ]
176
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, u32 > {
177
+ $submac!( i, $( $args) * )
178
+ }
179
+ ) ;
180
+ ( pub ( crate ) $name: ident<$o: ty>, $submac: ident!( $( $args: tt) * ) ) => (
181
+ #[ allow( unused_variables) ]
182
+ pub ( crate ) fn $name( i: & [ u8 ] ) -> $crate:: IResult <& [ u8 ] , $o, u32 > {
183
+ $submac!( i, $( $args) * )
184
+ }
185
+ ) ;
186
+ ( pub ( crate ) $name: ident, $submac: ident!( $( $args: tt) * ) ) => (
187
+ #[ allow( unused_variables) ]
188
+ pub ( crate ) fn $name<' a>( i: & ' a [ u8 ] ) -> $crate:: IResult <& [ u8 ] , & [ u8 ] , u32 > {
189
+ $submac!( i, $( $args) * )
190
+ }
191
+ ) ;
160
192
) ;
161
193
162
194
/// Makes a function from a parser combination with arguments.
@@ -172,6 +204,16 @@ macro_rules! named_args {
172
204
$submac!( input, $( $args) * )
173
205
}
174
206
} ;
207
+ ( pub ( crate ) $func_name: ident ( $( $arg: ident : $typ: ty ) ,* ) < $return_type: ty > , $submac: ident!( $( $args: tt) * ) ) => {
208
+ pub ( crate ) fn $func_name( input: & [ u8 ] , $( $arg : $typ ) ,* ) -> $crate:: IResult <& [ u8 ] , $return_type> {
209
+ $submac!( input, $( $args) * )
210
+ }
211
+ } ;
212
+ ( pub ( crate ) $func_name: ident < ' a > ( $( $arg: ident : $typ: ty ) ,* ) < $return_type: ty > , $submac: ident!( $( $args: tt) * ) ) => {
213
+ pub ( crate ) fn $func_name<' this_is_probably_unique_i_hope_please, ' a>( input: & ' this_is_probably_unique_i_hope_please [ u8 ] , $( $arg : $typ ) ,* ) -> $crate:: IResult <& ' this_is_probably_unique_i_hope_please [ u8 ] , $return_type> {
214
+ $submac!( input, $( $args) * )
215
+ }
216
+ } ;
175
217
( $func_name: ident ( $( $arg: ident : $typ: ty ) ,* ) < $return_type: ty > , $submac: ident!( $( $args: tt) * ) ) => {
176
218
fn $func_name( input: & [ u8 ] , $( $arg : $typ ) ,* ) -> $crate:: IResult <& [ u8 ] , $return_type> {
177
219
$submac!( input, $( $args) * )
@@ -260,6 +302,36 @@ macro_rules! named_attr (
260
302
$submac!( i, $( $args) * )
261
303
}
262
304
) ;
305
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident( $i: ty ) -> $o: ty, $submac: ident!( $( $args: tt) * ) ) => (
306
+ $( #[ $attr] ) *
307
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, u32 > {
308
+ $submac!( i, $( $args) * )
309
+ }
310
+ ) ;
311
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident<$i: ty, $o: ty, $e: ty>, $submac: ident!( $( $args: tt) * ) ) => (
312
+ $( #[ $attr] ) *
313
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, $e> {
314
+ $submac!( i, $( $args) * )
315
+ }
316
+ ) ;
317
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident<$i: ty, $o: ty>, $submac: ident!( $( $args: tt) * ) ) => (
318
+ $( #[ $attr] ) *
319
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, u32 > {
320
+ $submac!( i, $( $args) * )
321
+ }
322
+ ) ;
323
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident<$o: ty>, $submac: ident!( $( $args: tt) * ) ) => (
324
+ $( #[ $attr] ) *
325
+ pub ( crate ) fn $name( i: & [ u8 ] ) -> $crate:: IResult <& [ u8 ] , $o, u32 > {
326
+ $submac!( i, $( $args) * )
327
+ }
328
+ ) ;
329
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident, $submac: ident!( $( $args: tt) * ) ) => (
330
+ $( #[ $attr] ) *
331
+ pub ( crate ) fn $name<' a>( i: & ' a [ u8 ] ) -> $crate:: IResult <& [ u8 ] , & [ u8 ] , u32 > {
332
+ $submac!( i, $( $args) * )
333
+ }
334
+ ) ;
263
335
) ;
264
336
265
337
/// Used to wrap common expressions and function as macros
@@ -1228,6 +1300,17 @@ mod tests {
1228
1300
assert_eq ! ( res, Done ( & b"" [ ..] , a) ) ;
1229
1301
}
1230
1302
1303
+ mod pub_crate_named_mod {
1304
+ named ! ( pub ( crate ) tst, tag!( "abcd" ) ) ;
1305
+ }
1306
+
1307
+ #[ test]
1308
+ fn pub_crate_named_test ( ) {
1309
+ let a = & b"abcd" [ ..] ;
1310
+ let res = pub_crate_named_mod:: tst ( a) ;
1311
+ assert_eq ! ( res, Done ( & b"" [ ..] , a) ) ;
1312
+ }
1313
+
1231
1314
#[ test]
1232
1315
fn apply_test ( ) {
1233
1316
fn sum2 ( a : u8 , b : u8 ) -> u8 { a + b }
0 commit comments