pub trait Schema: Send + Sync + 'static {
    // Required methods
    fn schema_name() -> SchemaName;
    fn define_collections(schema: &mut Schematic) -> Result<(), Error>;

    // Provided method
    fn schematic() -> Result<Schematic, Error> { ... }
}
Expand description

Defines a group of collections that are stored into a single database.

Deriving this trait

This trait can be derived rather than manually implemented:

use bonsaidb_core::schema::{Collection, Schema};
use serde::{Deserialize, Serialize};

#[derive(Schema)]
#[schema(name = "MySchema", collections = [MyCollection])]
pub struct MySchema;

#[derive(Serialize, Deserialize, Default, Collection)]
#[collection(name = "MyCollection")]
pub struct MyCollection {
    pub rank: u32,
    pub score: f32,
}

If you’re publishing a schema for use in multiple projects, consider giving the schema an authority, which gives your schema a namespace:

use bonsaidb_core::schema::Schema;

#[derive(Schema)]
#[schema(name = "MySchema", authority = "khonsulabs", collections = [MyCollection])]
pub struct MySchema;

Required Methods§

source

fn schema_name() -> SchemaName

Returns the unique SchemaName for this schema.

source

fn define_collections(schema: &mut Schematic) -> Result<(), Error>

Defines the Collections into schema.

Provided Methods§

source

fn schematic() -> Result<Schematic, Error>

Retrieves the Schematic for this schema.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Schema for ()

This implementation is for accessing databases when interacting with collections isn’t required. For example, accessing only the key-value store or pubsub.

Implementors§

source§

impl Schema for Admin

source§

impl Schema for BasicSchema

source§

impl<T> Schema for T
where T: Collection + 'static,