1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
mod collection;
mod names;
mod schematic;
pub mod view;
use std::fmt::Debug;
pub use self::{
    collection::{
        Collection, DefaultSerialization, Entry, InsertError, List, NamedCollection,
        NamedReference, SerializedCollection,
    },
    names::{Authority, CollectionName, InvalidNameError, Name, SchemaName, ViewName},
    schematic::Schematic,
    view::{
        map::{Map, MappedValue, ViewMappedValue},
        CollectionViewSchema, DefaultViewSerialization, Key, ReduceResult, SerializedView, View,
        ViewMapResult, ViewSchema,
    },
};
use crate::Error;
pub trait Schema: Send + Sync + Debug + 'static {
    
    fn schema_name() -> SchemaName;
    
    fn define_collections(schema: &mut Schematic) -> Result<(), Error>;
    
    fn schematic() -> Result<Schematic, Error> {
        Schematic::from_schema::<Self>()
    }
}
impl Schema for () {
    fn schema_name() -> SchemaName {
        SchemaName::new("", "")
    }
    fn define_collections(_schema: &mut Schematic) -> Result<(), Error> {
        Ok(())
    }
}
impl<T> Schema for T
where
    T: Collection + 'static,
{
    fn schema_name() -> SchemaName {
        let CollectionName { authority, name } = Self::collection_name();
        SchemaName { authority, name }
    }
    fn define_collections(schema: &mut Schematic) -> Result<(), Error> {
        schema.define_collection::<Self>()
    }
}