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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
/*! # Types and traits for storable documents ## Document trait The basic trait which should be implemented for structs which designed to be handled as documents. ```rust use serde::{Serialize, Deserialize}; use ledb_types::{Document, Identifier, Primary, KeyFields, KeyType, IndexKind}; #[derive(Serialize, Deserialize)] struct MyDoc { // define optional primary key field id: Option<Primary>, // define other fields title: String, tag: Vec<String>, timestamp: u32, // define nested document meta: MetaData, } #[derive(Serialize, Deserialize)] struct MetaData { // define index field keywords: Vec<String>, // define other fields description: String, } impl Document for MyDoc { // declare primary key field name fn primary_field() -> Identifier { "id".into() } // declare other key fields fn key_fields() -> KeyFields { KeyFields::new() // add key fields of document .with_field(("title", KeyType::String, IndexKind::Unique)) .with_field(("tag", KeyType::String, IndexKind::Index)) .with_field(("timestamp", KeyType::Int, IndexKind::Unique)) // add key fields from nested document .with_fields(MetaData::key_fields().with_parent("meta")) } } impl Document for MetaData { // declare key fields for index fn key_fields() -> KeyFields { KeyFields::new() // add key fields of document .with_field(("keywords", KeyType::String, IndexKind::Index)) } } ``` ## DocumentKeyType trait This trait maps rust types to key types. */ //#[cfg(feature = "json")] //extern crate serde_json; //#[cfg(feature = "cbor")] //extern crate serde_cbor; //#[cfg(feature = "bytes")] //extern crate bytes; mod document; mod identifier; mod index; pub use self::document::*; pub use self::identifier::*; pub use self::index::*;