use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; use std::error::Error; use std::ops::Deref; use std::sync::Arc; use rocksdb::rocksdb::{DB, Snapshot}; pub use self::index::Index; pub use self::update::{Update, UpdateBuilder}; pub use self::document_key::{DocumentKey, DocumentKeyAttr}; pub use self::database_view::{DatabaseView, DocumentIter}; pub use self::database::Database; pub use self::schema::Schema; const DATA_INDEX: &[u8] = b"data-index"; const DATA_SCHEMA: &[u8] = b"data-schema"; macro_rules! forward_to_unserializable_type { ($($ty:ident => $se_method:ident,)*) => { $( fn $se_method(self, _v: $ty) -> Result { Err(SerializerError::UnserializableType { name: "$ty" }) } )* } } pub mod schema; pub(crate) mod index; mod update; mod database; mod document_key; mod database_view; mod deserializer; fn calculate_hash(t: &T) -> u64 { let mut s = DefaultHasher::new(); t.hash(&mut s); s.finish() } fn retrieve_data_schema(snapshot: &Snapshot) -> Result> where D: Deref { match snapshot.get(DATA_SCHEMA)? { Some(vector) => Ok(Schema::read_from_bin(&*vector)?), None => Err(String::from("BUG: no schema found in the database").into()), } } fn retrieve_data_index(snapshot: &Snapshot) -> Result> where D: Deref { match snapshot.get(DATA_INDEX)? { Some(vector) => { let bytes_len = vector.as_ref().len(); let bytes = Arc::new(vector.as_ref().to_vec()); Ok(Index::from_shared_bytes(bytes, 0, bytes_len)?) }, None => Ok(Index::default()), } }