Skip to content

Commit 8b812d5

Browse files
authored
Merge pull request #1005 from nnethercote/improve-extension_trait
Improve `extension_trait!`
2 parents b90c2cd + db7c194 commit 8b812d5

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

Diff for: src/utils.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ macro_rules! extension_trait {
281281
#[cfg(feature = "docs")]
282282
#[doc = $doc]
283283
pub trait $name {
284-
extension_trait!(@doc () $($body_base)* $($body_ext)*);
284+
extension_trait!(@doc [$($body_base)* $($body_ext)*] -> []);
285285
}
286286

287287
// When not rendering docs, re-export the base trait from the futures crate.
@@ -291,7 +291,7 @@ macro_rules! extension_trait {
291291
// The extension trait that adds methods to any type implementing the base trait.
292292
#[doc = $doc_ext]
293293
pub trait $ext: $name {
294-
extension_trait!(@ext () $($body_ext)*);
294+
extension_trait!(@ext [$($body_ext)*] -> []);
295295
}
296296

297297
// Blanket implementation of the extension trait for any type implementing the base trait.
@@ -302,32 +302,24 @@ macro_rules! extension_trait {
302302
};
303303

304304
// Parse the return type in an extension method.
305-
(@doc ($($head:tt)*) -> impl Future<Output = $out:ty> $(+ $lt:lifetime)? [$f:ty] $($tail:tt)*) => {
306-
extension_trait!(@doc ($($head)* -> owned::ImplFuture<$out>) $($tail)*);
305+
(@doc [-> impl Future<Output = $out:ty> $(+ $lt:lifetime)? [$f:ty] $($tail:tt)*] -> [$($accum:tt)*]) => {
306+
extension_trait!(@doc [$($tail)*] -> [$($accum)* -> owned::ImplFuture<$out>]);
307307
};
308-
(@ext ($($head:tt)*) -> impl Future<Output = $out:ty> $(+ $lt:lifetime)? [$f:ty] $($tail:tt)*) => {
309-
extension_trait!(@ext ($($head)* -> $f) $($tail)*);
310-
};
311-
312-
// Parse the return type in an extension method.
313-
(@doc ($($head:tt)*) -> impl Future<Output = $out:ty> + $lt:lifetime [$f:ty] $($tail:tt)*) => {
314-
extension_trait!(@doc ($($head)* -> borrowed::ImplFuture<$lt, $out>) $($tail)*);
315-
};
316-
(@ext ($($head:tt)*) -> impl Future<Output = $out:ty> + $lt:lifetime [$f:ty] $($tail:tt)*) => {
317-
extension_trait!(@ext ($($head)* -> $f) $($tail)*);
308+
(@ext [-> impl Future<Output = $out:ty> $(+ $lt:lifetime)? [$f:ty] $($tail:tt)*] -> [$($accum:tt)*]) => {
309+
extension_trait!(@ext [$($tail)*] -> [$($accum)* -> $f]);
318310
};
319311

320312
// Parse a token.
321-
(@doc ($($head:tt)*) $token:tt $($tail:tt)*) => {
322-
extension_trait!(@doc ($($head)* $token) $($tail)*);
313+
(@doc [$token:tt $($tail:tt)*] -> [$($accum:tt)*]) => {
314+
extension_trait!(@doc [$($tail)*] -> [$($accum)* $token]);
323315
};
324-
(@ext ($($head:tt)*) $token:tt $($tail:tt)*) => {
325-
extension_trait!(@ext ($($head)* $token) $($tail)*);
316+
(@ext [$token:tt $($tail:tt)*] -> [$($accum:tt)*]) => {
317+
extension_trait!(@ext [$($tail)*] -> [$($accum)* $token]);
326318
};
327319

328320
// Handle the end of the token list.
329-
(@doc ($($head:tt)*)) => { $($head)* };
330-
(@ext ($($head:tt)*)) => { $($head)* };
321+
(@doc [] -> [$($accum:tt)*]) => { $($accum)* };
322+
(@ext [] -> [$($accum:tt)*]) => { $($accum)* };
331323

332324
// Parse imports at the beginning of the macro.
333325
($import:item $($tail:tt)*) => {

0 commit comments

Comments
 (0)