Trait bones_lib::ecs::prelude::HasSchema

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) -> &T
where 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 T
where 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

§

impl HasSchema for String

§

fn schema() -> &'static Schema

§

impl HasSchema for Duration

§

fn schema() -> &'static Schema

§

impl HasSchema for BVec2

§

fn schema() -> &'static Schema

§

impl HasSchema for BVec3

§

fn schema() -> &'static Schema

§

impl HasSchema for BVec4

§

fn schema() -> &'static Schema

§

impl HasSchema for Quat

§

fn schema() -> &'static Schema

§

impl HasSchema for Vec4

§

fn schema() -> &'static Schema

§

impl HasSchema for Vec2

§

fn schema() -> &'static Schema

§

impl HasSchema for Vec3

§

fn schema() -> &'static Schema

§

impl HasSchema for DVec2

§

fn schema() -> &'static Schema

§

impl HasSchema for DVec3

§

fn schema() -> &'static Schema

§

impl HasSchema for DVec4

§

fn schema() -> &'static Schema

§

impl HasSchema for IVec2

§

fn schema() -> &'static Schema

§

impl HasSchema for IVec3

§

fn schema() -> &'static Schema

§

impl HasSchema for IVec4

§

fn schema() -> &'static Schema

§

impl HasSchema for UVec2

§

fn schema() -> &'static Schema

§

impl HasSchema for UVec3

§

fn schema() -> &'static Schema

§

impl HasSchema for UVec4

§

fn schema() -> &'static Schema

Implementors§