|
| 1 | +// force-host |
| 2 | +// no-prefer-dynamic |
| 3 | +// edition:2021 |
| 4 | + |
| 5 | +#![crate_type = "proc-macro"] |
| 6 | + |
| 7 | +extern crate proc_macro; |
| 8 | + |
| 9 | +use proc_macro::TokenStream; |
| 10 | + |
| 11 | +const TEMPLATE : &str = " |
| 12 | +type F<'a> = fn(&'a ()); |
| 13 | +
|
| 14 | +struct S<'a> { |
| 15 | + r: &'a VARIABLE, |
| 16 | + o: Box<F<'a>>, |
| 17 | +} |
| 18 | +
|
| 19 | +struct SAsyncSendTryBuilder< |
| 20 | + 'a, |
| 21 | + RBuilder_: for<'this> FnOnce( |
| 22 | + &'this Box<F<'a>>, |
| 23 | + ) -> Pin< |
| 24 | + Box<dyn Future<Output = Result<&'this VARIABLE, Error_>> + Send + 'this>, |
| 25 | + >, |
| 26 | + Error_, |
| 27 | +> { |
| 28 | + o: Box<F<'a>>, |
| 29 | + r_builder: RBuilder_, |
| 30 | +} |
| 31 | +impl<'a, RBuilder_: for<'this> FnOnce( |
| 32 | + &'this Box<F<'a>>, |
| 33 | + ) -> Pin< |
| 34 | + Box<dyn Future<Output = Result<&'this VARIABLE, Error_>> + Send + 'this>, |
| 35 | + >, |
| 36 | + Error_, |
| 37 | + > SAsyncSendTryBuilder<'a, RBuilder_, Error_> |
| 38 | +{ |
| 39 | + async fn try_build_or_recover(self) -> Result<S<'a>, (Error_, Heads<'a>)> { |
| 40 | + S::try_new_or_recover_async_send(self.o, self.r_builder).await |
| 41 | + } |
| 42 | +} |
| 43 | +struct Heads<'a> { |
| 44 | + o: Box<F<'a>>, |
| 45 | + _consume_template_lifetime_a: PhantomData<&'a ()>, |
| 46 | +} |
| 47 | +impl<'a> S<'a> { |
| 48 | + async fn try_new_or_recover_async_send<Error_>( |
| 49 | + o: Box<F<'a>>, |
| 50 | + r_builder: impl for<'this> FnOnce( |
| 51 | + &'this Box<F<'a>>, |
| 52 | + ) -> Pin< |
| 53 | + Box<dyn Future<Output = Result<&'this VARIABLE, Error_>> + Send + 'this>, |
| 54 | + >, |
| 55 | + ) -> Result<S<'a>, (Error_, Heads<'a>)> { |
| 56 | + todo!() |
| 57 | + } |
| 58 | +}"; |
| 59 | + |
| 60 | +#[proc_macro_derive(IncrementalMacro)] |
| 61 | +pub fn derive(input: TokenStream) -> TokenStream { |
| 62 | + #[cfg(cfail1)] let template_type = "u8"; |
| 63 | + #[cfg(cfail2)] let template_type = "str"; |
| 64 | + |
| 65 | + TEMPLATE |
| 66 | + .replace("VARIABLE", template_type) |
| 67 | + .parse() |
| 68 | + .unwrap() |
| 69 | +} |
0 commit comments