bevy_utils/object_safe.rs
1/// Assert that a given `T` is [object safe](https://doc.rust-lang.org/reference/items/traits.html#object-safety).
2/// Will fail to compile if that is not the case.
3///
4/// # Examples
5///
6/// ```rust
7/// # use bevy_utils::assert_object_safe;
8/// // Concrete types are always object safe
9/// struct MyStruct;
10/// assert_object_safe::<MyStruct>();
11///
12/// // Trait objects are where that safety comes into question.
13/// // This trait is object safe...
14/// trait ObjectSafe { }
15/// assert_object_safe::<dyn ObjectSafe>();
16/// ```
17///
18/// ```compile_fail
19/// # use bevy_utils::assert_object_safe;
20/// // ...but this trait is not.
21/// trait NotObjectSafe {
22/// const VALUE: usize;
23/// }
24/// assert_object_safe::<dyn NotObjectSafe>();
25/// // Error: the trait `NotObjectSafe` cannot be made into an object
26/// ```
27pub fn assert_object_safe<T: ?Sized>() {
28 // This space is left intentionally blank. The type parameter T is sufficient to induce a compiler
29 // error without a function body.
30}