Struct bones_schema::prelude::Schema

source ·
pub struct Schema { /* private fields */ }
Expand description

A schema registered with the SCHEMA_REGISTRY.

§Known Limitations

Currently there isn’t a known-safe way to construct a schema for a recursive struct. For example, this struct is troublesome:

struct Data {
    others: Vec<Data>,
}

This is because nested schemas are required to be a &'static Schema, and it would probalby require unsafe code to create a schema that references itself.

If this is a problem for your use-case, please open an issue. We would like to remove this limitation or find a suitable workaround in the future.

Implementations§

source§

impl Schema

source

pub fn represents(&self, other: &Schema) -> bool

Returns whether or not this schema represents the same memory layout as the other schema, and you can safely cast a pointer to one to a pointer to the other.

source§

impl Schema

source

pub fn id(&self) -> SchemaId

Get the registered, unique ID of the Schema.

source

pub fn schema(&self) -> &SchemaData

Get a static reference to the Schema that was registered.

source

pub fn layout(&self) -> Layout

Get the Layout of the Schema.

source

pub fn field_offsets(&self) -> &'static [(Option<String>, usize)]

If this schema represents a struct, this returns the list of fields, with the names of the fields, and their byte offsets from the beginning of the struct.

source

pub fn ensure_match(&self, other: &Self) -> Result<(), SchemaMismatchError>

Helper function to make sure that this schema matches another or return a SchemaMismatchError.