genawaiter/
macros.rs

1/// Yields a value from a generator.
2///
3/// This macro can only be used inside the `gen!` and `producer!` families of
4/// macros.
5///
6/// It will suspend execution of the function until the generator is resumed. At
7/// that time, it will evaluate to the resume argument, if given, otherwise it
8/// will evaluate to `()`.
9///
10/// # Examples
11///
12/// [_See the module-level docs for examples._](.)
13#[cfg(feature = "proc_macro")]
14#[macro_export]
15macro_rules! yield_ {
16    ($val:expr) => {
17        compile_error!(
18            "`yield_!()` can only be used inside one of the genawaiter macros",
19        )
20    };
21    (@__impl => $co:expr, $value:expr) => {
22        $co.yield_($value).await
23    };
24}
25
26// Internal use only. This is a copy of `futures::pin_mut!` so we can avoid
27// pulling in a dependency for a two-liner.
28#[cfg(feature = "futures03")]
29macro_rules! pin_mut {
30    ($x:ident) => {
31        let mut $x = $x;
32        #[allow(unused_mut)]
33        let mut $x = unsafe { ::std::pin::Pin::new_unchecked(&mut $x) };
34    };
35}