
# Objective Edition 2021 requires `dyn Trait` and it won't compile without `dyn`. ## Solution Added `dyn`.
19 lines
578 B
Rust
19 lines
578 B
Rust
use proc_macro::TokenStream;
|
|
use quote::quote;
|
|
use syn::{parse_macro_input, DeriveInput};
|
|
|
|
pub fn derive_dynamic_plugin(input: TokenStream) -> TokenStream {
|
|
let ast = parse_macro_input!(input as DeriveInput);
|
|
let struct_name = &ast.ident;
|
|
|
|
TokenStream::from(quote! {
|
|
#[no_mangle]
|
|
pub extern "C" fn _bevy_create_plugin() -> *mut dyn bevy::app::Plugin {
|
|
// make sure the constructor is the correct type.
|
|
let object = #struct_name {};
|
|
let boxed = Box::new(object);
|
|
Box::into_raw(boxed)
|
|
}
|
|
})
|
|
}
|