pub unsafe trait HasSchema: Sync + Send + 'static {
    // Required method
    fn schema() -> &'static Schema;

    // Provided methods
    fn register_schema() { ... }
    fn cast<T>(this: &Self) -> &T
       where T: HasSchema { ... }
    fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>
       where T: HasSchema { ... }
    fn cast_mut<T>(this: &mut Self) -> &mut T
       where T: HasSchema { ... }
    fn try_cast_mut<T>(this: &mut Self) -> Result<&mut T, SchemaMismatchError>
       where T: HasSchema { ... }
    fn as_schema_ref(&self) -> SchemaRef<'_>
       where Self: Sized { ... }
    fn as_schema_mut(&mut self) -> SchemaRefMut<'_>
       where Self: Sized { ... }
}
Expand description

Trait implemented for types that have a [Schema].

Safety

This trait is unsafe to implement manually because it makes claims about the memory layout of a type that may be depended on in unsafe code, but it is safe to derive HasSchema on supported types.

If implemented manually, you must ensure that the schema accurately describes the memory layout of the type, or else accessing the type according to the schema would be unsound.

Required Methods§

fn schema() -> &'static Schema

Get this type’s [Schema].

Provided Methods§

fn register_schema()

Register this schema with the global schema registry.

This is automatically done by the framework in many cases, whenever schema() is called, but it may be necessary sometimes to manually register it.

fn cast<T>(this: &Self) -> &Twhere T: HasSchema,

Cast a reference of this type to a reference of another type with the same memory layout.

Panics

Panics if the schema of T doesn’t match the schema of Self.

fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where T: HasSchema,

Cast a reference of this type to a reference of another type with the same memory layout.

Errors

Errors if the schema of T doesn’t match the schema of Self.

fn cast_mut<T>(this: &mut Self) -> &mut Twhere T: HasSchema,

Cast a mutable reference of this type to a reference of another type with the same memory layout.

Panics

Panics if the schema of T doesn’t match the schema of Self.

fn try_cast_mut<T>(this: &mut Self) -> Result<&mut T, SchemaMismatchError>where T: HasSchema,

Cast a mutable reference of this type to a reference of another type with the same memory layout.

Errors

Errors if the schema of T doesn’t match the schema of Self.

fn as_schema_ref(&self) -> SchemaRef<'_>where Self: Sized,

Converts a reference of T to a SchemaRef

fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where Self: Sized,

Converts a reference of T to a SchemaRefMut

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl HasSchema for bool

§

fn schema() -> &'static Schema

§

impl HasSchema for f32

§

fn schema() -> &'static Schema

§

impl HasSchema for f64

§

fn schema() -> &'static Schema

§

impl HasSchema for i8

§

fn schema() -> &'static Schema

§

impl HasSchema for i16

§

fn schema() -> &'static Schema

§

impl HasSchema for i32

§

fn schema() -> &'static Schema

§

impl HasSchema for i64

§

fn schema() -> &'static Schema

§

impl HasSchema for i128

§

fn schema() -> &'static Schema

§

impl HasSchema for isize

§

fn schema() -> &'static Schema

§

impl HasSchema for u8

§

fn schema() -> &'static Schema

§

impl HasSchema for u16

§

fn schema() -> &'static Schema

§

impl HasSchema for u32

§

fn schema() -> &'static Schema

§

impl HasSchema for u64

§

fn schema() -> &'static Schema

§

impl HasSchema for u128

§

fn schema() -> &'static Schema

§

impl HasSchema for ()

§

fn schema() -> &'static Schema

§

impl HasSchema for usize

§

fn schema() -> &'static Schema

Implementors§

§

impl HasSchema for AssetKind

source§

impl HasSchema for ButtonState

source§

impl HasSchema for GamepadAxis

source§

impl HasSchema for GamepadButton

source§

impl HasSchema for GamepadConnectionEventKind

source§

impl HasSchema for GamepadEvent

source§

impl HasSchema for KeyCode

source§

impl HasSchema for CameraSize

source§

impl HasSchema for Color

source§

impl HasSchema for Image

source§

impl HasSchema for AnimatedSprite

source§

impl HasSchema for AnimationBankSprite

§

impl HasSchema for String

§

impl HasSchema for Ustr

§

impl HasSchema for AssetServer

§

impl HasSchema for SchemaAssetHandle

§

impl HasSchema for SchemaBox

§

impl HasSchema for SchemaDeserialize

§

impl HasSchema for SchemaMetaAssetLoader

§

impl HasSchema for UntypedHandle

source§

impl HasSchema for FrameDiagState

§

impl HasSchema for BVec2

§

impl HasSchema for BVec3

§

impl HasSchema for BVec4

§

impl HasSchema for DVec2

§

impl HasSchema for DVec3

§

impl HasSchema for DVec4

§

impl HasSchema for IVec2

§

impl HasSchema for IVec3

§

impl HasSchema for IVec4

§

impl HasSchema for Quat

§

impl HasSchema for UVec2

§

impl HasSchema for UVec3

§

impl HasSchema for UVec4

§

impl HasSchema for Vec2

§

impl HasSchema for Vec3

§

impl HasSchema for Vec4

source§

impl HasSchema for GamepadAxisEvent

source§

impl HasSchema for GamepadButtonEvent

source§

impl HasSchema for GamepadConnectionEvent

source§

impl HasSchema for GamepadInputs

source§

impl HasSchema for KeyboardEvent

source§

impl HasSchema for KeyboardInputs

source§

impl HasSchema for MouseInputs

source§

impl HasSchema for Window

source§

impl HasSchema for CommandQueue

source§

impl HasSchema for CurrentSystemStage

source§

impl HasSchema for Entities

source§

impl HasSchema for Entity

§

impl HasSchema for Duration

source§

impl HasSchema for SessionOptions

source§

impl HasSchema for Sessions

source§

impl HasSchema for Time

source§

impl HasSchema for FluentBundleAsset

source§

impl HasSchema for FluentResourceAsset

source§

impl HasSchema for LocalizationAsset

source§

impl HasSchema for RootLocalizationFieldIdx

source§

impl HasSchema for NetworkDebug

source§

impl HasSchema for DisconnectedPlayers

source§

impl HasSchema for NetworkInfo

source§

impl HasSchema for NetworkMatchSocket

source§

impl HasSchema for AudioManager

source§

impl HasSchema for AudioSource

source§

impl HasSchema for Camera

source§

impl HasSchema for CameraShake

source§

impl HasSchema for CameraTraumaEvents

source§

impl HasSchema for ClearColor

source§

impl HasSchema for ShakeNoise

source§

impl HasSchema for Viewport

source§

impl HasSchema for Path2d

source§

impl HasSchema for Atlas

source§

impl HasSchema for AtlasCollisionTile

source§

impl HasSchema for AtlasSprite

source§

impl HasSchema for Sprite

source§

impl HasSchema for Renderer

source§

impl HasSchema for Tile

source§

impl HasSchema for TileLayer

source§

impl HasSchema for Transform

source§

impl HasSchema for EguiCtx

source§

impl HasSchema for EguiInputHook

source§

impl HasSchema for EguiSettings

source§

impl HasSchema for EguiTextures

source§

impl HasSchema for Font

source§

impl HasSchema for FontMeta

source§

impl HasSchema for BorderImageMeta

source§

impl HasSchema for ButtonBordersMeta

source§

impl HasSchema for ButtonThemeMeta

source§

impl HasSchema for MarginMeta

source§

impl HasSchema for Storage

source§

impl HasSchema for Timer

source§

impl HasSchema for SchemaLuaEcsRefMetatable

source§

impl HasSchema for LuaEngine

source§

impl HasSchema for LuaPlugin

source§

impl HasSchema for LuaPlugins

source§

impl HasSchema for LuaScript

§

impl<K, V> HasSchema for SMap<K, V>where K: HasSchema, V: HasSchema,

§

impl<T> HasSchema for Maybe<T>where T: HasSchema + Clone,

§

impl<T> HasSchema for Handle<T>where T: HasSchema,

§

impl<T> HasSchema for SBox<T>where T: HasSchema,

§

impl<T> HasSchema for SVec<T>where T: HasSchema,