@@ -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 (
@@ -147,6 +149,36 @@ macro_rules! named (
147
149
$submac!( i, $( $args) * )
148
150
}
149
151
) ;
152
+ ( pub ( crate ) $name: ident( $i: ty ) -> $o: ty, $submac: ident!( $( $args: tt) * ) ) => (
153
+ #[ allow( unused_variables) ]
154
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, u32 > {
155
+ $submac!( i, $( $args) * )
156
+ }
157
+ ) ;
158
+ ( pub ( crate ) $name: ident<$i: ty, $o: ty, $e: ty>, $submac: ident!( $( $args: tt) * ) ) => (
159
+ #[ allow( unused_variables) ]
160
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, $e> {
161
+ $submac!( i, $( $args) * )
162
+ }
163
+ ) ;
164
+ ( pub ( crate ) $name: ident<$i: ty, $o: ty>, $submac: ident!( $( $args: tt) * ) ) => (
165
+ #[ allow( unused_variables) ]
166
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, u32 > {
167
+ $submac!( i, $( $args) * )
168
+ }
169
+ ) ;
170
+ ( pub ( crate ) $name: ident<$o: ty>, $submac: ident!( $( $args: tt) * ) ) => (
171
+ #[ allow( unused_variables) ]
172
+ pub ( crate ) fn $name( i: & [ u8 ] ) -> $crate:: IResult <& [ u8 ] , $o, u32 > {
173
+ $submac!( i, $( $args) * )
174
+ }
175
+ ) ;
176
+ ( pub ( crate ) $name: ident, $submac: ident!( $( $args: tt) * ) ) => (
177
+ #[ allow( unused_variables) ]
178
+ pub ( crate ) fn $name<' a>( i: & ' a [ u8 ] ) -> $crate:: IResult <& [ u8 ] , & [ u8 ] , u32 > {
179
+ $submac!( i, $( $args) * )
180
+ }
181
+ ) ;
150
182
) ;
151
183
152
184
/// Makes a function from a parser combination with arguments.
@@ -192,6 +224,16 @@ macro_rules! named_args {
192
224
$submac!( input, $( $args) * )
193
225
}
194
226
} ;
227
+ ( pub ( crate ) $func_name: ident ( $( $arg: ident : $typ: ty ) ,* ) < $return_type: ty > , $submac: ident!( $( $args: tt) * ) ) => {
228
+ pub ( crate ) fn $func_name( input: & [ u8 ] , $( $arg : $typ ) ,* ) -> $crate:: IResult <& [ u8 ] , $return_type> {
229
+ $submac!( input, $( $args) * )
230
+ }
231
+ } ;
232
+ ( pub ( crate ) $func_name: ident < ' a > ( $( $arg: ident : $typ: ty ) ,* ) < $return_type: ty > , $submac: ident!( $( $args: tt) * ) ) => {
233
+ 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> {
234
+ $submac!( input, $( $args) * )
235
+ }
236
+ } ;
195
237
( $func_name: ident ( $( $arg: ident : $typ: ty ) ,* ) < $return_type: ty > , $submac: ident!( $( $args: tt) * ) ) => {
196
238
fn $func_name( input: & [ u8 ] , $( $arg : $typ ) ,* ) -> $crate:: IResult <& [ u8 ] , $return_type> {
197
239
$submac!( input, $( $args) * )
@@ -309,6 +351,36 @@ macro_rules! named_attr (
309
351
$submac!( i, $( $args) * )
310
352
}
311
353
) ;
354
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident( $i: ty ) -> $o: ty, $submac: ident!( $( $args: tt) * ) ) => (
355
+ $( #[ $attr] ) *
356
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, u32 > {
357
+ $submac!( i, $( $args) * )
358
+ }
359
+ ) ;
360
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident<$i: ty, $o: ty, $e: ty>, $submac: ident!( $( $args: tt) * ) ) => (
361
+ $( #[ $attr] ) *
362
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, $e> {
363
+ $submac!( i, $( $args) * )
364
+ }
365
+ ) ;
366
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident<$i: ty, $o: ty>, $submac: ident!( $( $args: tt) * ) ) => (
367
+ $( #[ $attr] ) *
368
+ pub ( crate ) fn $name( i: $i ) -> $crate:: IResult <$i, $o, u32 > {
369
+ $submac!( i, $( $args) * )
370
+ }
371
+ ) ;
372
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident<$o: ty>, $submac: ident!( $( $args: tt) * ) ) => (
373
+ $( #[ $attr] ) *
374
+ pub ( crate ) fn $name( i: & [ u8 ] ) -> $crate:: IResult <& [ u8 ] , $o, u32 > {
375
+ $submac!( i, $( $args) * )
376
+ }
377
+ ) ;
378
+ ( $( #[ $attr: meta] ) * , pub ( crate ) $name: ident, $submac: ident!( $( $args: tt) * ) ) => (
379
+ $( #[ $attr] ) *
380
+ pub ( crate ) fn $name<' a>( i: & ' a [ u8 ] ) -> $crate:: IResult <& [ u8 ] , & [ u8 ] , u32 > {
381
+ $submac!( i, $( $args) * )
382
+ }
383
+ ) ;
312
384
) ;
313
385
314
386
/// Used to wrap common expressions and function as macros
@@ -1366,6 +1438,17 @@ mod tests {
1366
1438
assert_eq ! ( res, Ok ( ( & b"" [ ..] , a) ) ) ;
1367
1439
}
1368
1440
1441
+ mod pub_crate_named_mod {
1442
+ named ! ( pub ( crate ) tst, tag!( "abcd" ) ) ;
1443
+ }
1444
+
1445
+ #[ test]
1446
+ fn pub_crate_named_test ( ) {
1447
+ let a = & b"abcd" [ ..] ;
1448
+ let res = pub_crate_named_mod:: tst ( a) ;
1449
+ assert_eq ! ( res, Done ( & b"" [ ..] , a) ) ;
1450
+ }
1451
+
1369
1452
#[ test]
1370
1453
fn apply_test ( ) {
1371
1454
fn sum2 ( a : u8 , b : u8 ) -> u8 {
0 commit comments