Trait bones_schema::prelude::HasSchema

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

    // Provided methods
    fn register_schema() { ... }
    fn cast<T: HasSchema>(this: &Self) -> &T { ... }
    fn try_cast<T: HasSchema>(this: &Self) -> Result<&T, SchemaMismatchError> { ... }
    fn cast_mut<T: HasSchema>(this: &mut Self) -> &mut T { ... }
    fn try_cast_mut<T: HasSchema>(
        this: &mut Self,
    ) -> Result<&mut T, SchemaMismatchError> { ... }
    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§

source

fn schema() -> &'static Schema

Get this type’s Schema.

Provided Methods§

source

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.

source

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

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.

source

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

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.

source

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

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.

source

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

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.

source

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

Converts a reference of T to a SchemaRef

source

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§

source§

impl HasSchema for bool

source§

fn schema() -> &'static Schema

source§

impl HasSchema for f32

source§

fn schema() -> &'static Schema

source§

impl HasSchema for f64

source§

fn schema() -> &'static Schema

source§

impl HasSchema for i8

source§

fn schema() -> &'static Schema

source§

impl HasSchema for i16

source§

fn schema() -> &'static Schema

source§

impl HasSchema for i32

source§

fn schema() -> &'static Schema

source§

impl HasSchema for i64

source§

fn schema() -> &'static Schema

source§

impl HasSchema for i128

source§

fn schema() -> &'static Schema

source§

impl HasSchema for isize

source§

fn schema() -> &'static Schema

source§

impl HasSchema for u8

source§

fn schema() -> &'static Schema

source§

impl HasSchema for u16

source§

fn schema() -> &'static Schema

source§

impl HasSchema for u32

source§

fn schema() -> &'static Schema

source§

impl HasSchema for u64

source§

fn schema() -> &'static Schema

source§

impl HasSchema for u128

source§

fn schema() -> &'static Schema

source§

impl HasSchema for ()

source§

fn schema() -> &'static Schema

source§

impl HasSchema for usize

source§

fn schema() -> &'static Schema

source§

impl HasSchema for String

source§

fn schema() -> &'static Schema

source§

impl HasSchema for Duration

source§

fn schema() -> &'static Schema

source§

impl HasSchema for BVec2

source§

fn schema() -> &'static Schema

source§

impl HasSchema for BVec3

source§

fn schema() -> &'static Schema

source§

impl HasSchema for BVec4

source§

fn schema() -> &'static Schema

source§

impl HasSchema for Quat

source§

fn schema() -> &'static Schema

source§

impl HasSchema for Vec4

source§

fn schema() -> &'static Schema

source§

impl HasSchema for Vec2

source§

fn schema() -> &'static Schema

source§

impl HasSchema for Vec3

source§

fn schema() -> &'static Schema

source§

impl HasSchema for DVec2

source§

fn schema() -> &'static Schema

source§

impl HasSchema for DVec3

source§

fn schema() -> &'static Schema

source§

impl HasSchema for DVec4

source§

fn schema() -> &'static Schema

source§

impl HasSchema for IVec2

source§

fn schema() -> &'static Schema

source§

impl HasSchema for IVec3

source§

fn schema() -> &'static Schema

source§

impl HasSchema for IVec4

source§

fn schema() -> &'static Schema

source§

impl HasSchema for UVec2

source§

fn schema() -> &'static Schema

source§

impl HasSchema for UVec3

source§

fn schema() -> &'static Schema

source§

impl HasSchema for UVec4

source§

fn schema() -> &'static Schema

source§

impl HasSchema for Ustr

source§

fn schema() -> &'static Schema

Implementors§