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§
Sourcefn schema_name() -> SchemaName
fn schema_name() -> SchemaName
Returns the unique SchemaName for this schema.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so 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.
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.