fn add_async_trait(mut parsed: ItemTrait) -> TokenStream {
let output = quote! {
- #[cfg(all(not(target_arch = "wasm32"), not(feature = "async-interface")))]
+ #[cfg(not(feature = "async-interface"))]
#parsed
};
let output = quote! {
#output
- #[cfg(any(target_arch = "wasm32", feature = "async-interface"))]
+ #[cfg(feature = "async-interface")]
#[async_trait(?Send)]
#parsed
};
fn add_async_method(mut parsed: ImplItemMethod) -> TokenStream {
let output = quote! {
- #[cfg(all(not(target_arch = "wasm32"), not(feature = "async-interface")))]
+ #[cfg(not(feature = "async-interface"))]
#parsed
};
let output = quote! {
#output
- #[cfg(any(target_arch = "wasm32", feature = "async-interface"))]
+ #[cfg(feature = "async-interface")]
#parsed
};
fn add_async_impl_trait(mut parsed: ItemImpl) -> TokenStream {
let output = quote! {
- #[cfg(all(not(target_arch = "wasm32"), not(feature = "async-interface")))]
+ #[cfg(not(feature = "async-interface"))]
#parsed
};
let output = quote! {
#output
- #[cfg(any(target_arch = "wasm32", feature = "async-interface"))]
+ #[cfg(feature = "async-interface")]
#[async_trait(?Send)]
#parsed
};
output.into()
}
-/// Makes a method or every method of a trait "async" only if the target_arch is "wasm32"
+/// Makes a method or every method of a trait `async`, if the `async-interface` feature is enabled.
///
/// Requires the `async-trait` crate as a dependency whenever this attribute is used on a trait
/// definition or trait implementation.
}
}
-/// Awaits if target_arch is "wasm32", does nothing otherwise
+/// Awaits, if the `async-interface` feature is enabled.
#[proc_macro]
pub fn maybe_await(expr: TokenStream) -> TokenStream {
let expr: proc_macro2::TokenStream = expr.into();
let quoted = quote! {
{
- #[cfg(all(not(target_arch = "wasm32"), not(feature = "async-interface")))]
+ #[cfg(not(feature = "async-interface"))]
{
#expr
}
- #[cfg(any(target_arch = "wasm32", feature = "async-interface"))]
+ #[cfg(feature = "async-interface")]
{
#expr.await
}
quoted.into()
}
-/// Awaits if target_arch is "wasm32", uses `tokio::Runtime::block_on()` otherwise
+/// Awaits, if the `async-interface` feature is enabled, uses `tokio::Runtime::block_on()` otherwise
///
-/// Requires the `tokio` crate as a dependecy with `rt-core` or `rt-threaded` to build on non-wasm32 platforms.
+/// Requires the `tokio` crate as a dependecy with `rt-core` or `rt-threaded` to build.
#[proc_macro]
pub fn await_or_block(expr: TokenStream) -> TokenStream {
let expr: proc_macro2::TokenStream = expr.into();
let quoted = quote! {
{
- #[cfg(all(not(target_arch = "wasm32"), not(feature = "async-interface")))]
+ #[cfg(not(feature = "async-interface"))]
{
tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(#expr)
}
- #[cfg(any(target_arch = "wasm32", feature = "async-interface"))]
+ #[cfg(feature = "async-interface")]
{
#expr.await
}
/// operations to build a blockchain for a given wallet, so if a wallet needs to be synced
/// often it's recommended to use [`BlockchainFactory::build_for_wallet`] to reuse the same
/// blockchain multiple times.
- #[cfg(not(any(target_arch = "wasm32", feature = "async-interface")))]
- #[cfg_attr(
- docsrs,
- doc(cfg(not(any(target_arch = "wasm32", feature = "async-interface"))))
- )]
+ #[cfg(not(feature = "async-interface"))]
+ #[cfg_attr(docsrs, doc(cfg(not(feature = "async-interface"))))]
fn sync_wallet<D: BatchDatabase>(
&self,
wallet: &Wallet<D>,