bevy/examples/reflection/generic_reflection.rs
MinerSebas 8f363544ad Reorder Imports in Examples (#1598)
This only affected 2 Examples:
* `generic_reflection`: For some reason, a `pub use` statement was used. This was removed, and alphabetically ordered.
* `wireframe`: This example used the `bevy_internal` crate directly. Changed to use `bevy` instead.

All other Example Imports are correct.

One potential subjective change is the `removel_detection` example. 
Unlike all other Examples, it has its (first) explanatory comment before the Imports.
2021-03-09 01:07:01 +00:00

26 lines
758 B
Rust

use bevy::{prelude::*, reflect::TypeRegistry};
use std::any::TypeId;
/// You must manually register each instance of a generic type
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.register_type::<MyType<u32>>()
.add_startup_system(setup.system())
.run();
}
#[derive(Reflect)]
struct MyType<T: Reflect> {
value: T,
}
fn setup(type_registry: Res<TypeRegistry>) {
let type_registry = type_registry.read();
let registration = type_registry.get(TypeId::of::<MyType<u32>>()).unwrap();
println!("Registration for {} exists", registration.short_name());
// MyType<String> was not manually registered, so it does not exist
assert!(type_registry.get(TypeId::of::<MyType<String>>()).is_none());
}