Trait bones_framework::asset::prelude::HasSchema
source · 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§
Provided Methods§
sourcefn register_schema()
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.
sourcefn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
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
.
sourcefn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
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
.
sourcefn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
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
.
sourcefn try_cast_mut<T>(this: &mut Self) -> Result<&mut T, SchemaMismatchError>where
T: HasSchema,
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
.
sourcefn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
Converts a reference of T
to a SchemaRef
sourcefn as_schema_mut(&mut self) -> SchemaRefMut<'_>where
Self: Sized,
fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where
Self: Sized,
Converts a reference of T
to a SchemaRefMut