Commit missing matrix_sdk_common_macros folder
parent
8b77b4171a
commit
f07ac5d679
|
@ -0,0 +1,18 @@
|
||||||
|
[package]
|
||||||
|
description = "Helper macros for the Matrix SDK"
|
||||||
|
authors = ["MTRnord <mtrnord1@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
homepage = "https://github.com/matrix-org/matrix-rust-sdk"
|
||||||
|
keywords = ["matrix", "chat", "messaging", "ruma"]
|
||||||
|
license = "Apache-2.0"
|
||||||
|
name = "matrix-sdk-common-macros"
|
||||||
|
readme = "README.md"
|
||||||
|
repository = "https://github.com/matrix-org/matrix-rust-sdk"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syn = "1.0"
|
||||||
|
quote = "1.0"
|
|
@ -0,0 +1,30 @@
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
use syn::{parse_macro_input, parse_quote, ItemTrait};
|
||||||
|
|
||||||
|
/// Attribute to use `Send + Sync` for everything but wasm32
|
||||||
|
#[proc_macro_attribute]
|
||||||
|
pub fn send_sync(_attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
|
// Parse the input tokens into a syntax tree
|
||||||
|
let mut input = parse_macro_input!(input as ItemTrait);
|
||||||
|
|
||||||
|
let send_trait_bound = parse_quote!(std::marker::Send);
|
||||||
|
let sync_trait_bound = parse_quote!(std::marker::Sync);
|
||||||
|
input.supertraits.push(send_trait_bound);
|
||||||
|
input.supertraits.push(sync_trait_bound);
|
||||||
|
|
||||||
|
TokenStream::from(quote!(#input))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A wasm32 compatible wrapper for the async_trait::async_trait macro
|
||||||
|
#[proc_macro_attribute]
|
||||||
|
pub fn async_trait(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
|
let attrs = r#"
|
||||||
|
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
|
||||||
|
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let mut out: TokenStream = attrs.parse().unwrap();
|
||||||
|
out.extend(item);
|
||||||
|
out
|
||||||
|
}
|
Loading…
Reference in New Issue