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

    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(Debug, Schema)]
#[schema(name = "MySchema", collections = [MyCollection])]
pub struct MySchema;

#[derive(Debug, 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(Debug, Schema)]
#[schema(name = "MySchema", authority = "khonsulabs", collections = [MyCollection])]
pub struct MySchema;

Required Methods§

Returns the unique SchemaName for this schema.

Defines the Collections into schema.

Provided Methods§

Retrieves the Schematic for this schema.

Implementations on Foreign Types§

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