use std::error::Error; use std::ops::Deref; use ::rocksdb::rocksdb::{DB, Snapshot}; use crate::index::schema::Schema; use crate::blob::PositiveBlob; use crate::DocumentId; pub trait Retrieve { fn schema(&self) -> Result, Box>; fn data_index(&self) -> Result>; fn get_documents(&self, ids: &[DocumentId]) -> Result, Box>; } impl Retrieve for Snapshot where T: Deref, { fn schema(&self) -> Result, Box> { match self.deref().get(b"data-schema")? { Some(value) => Ok(Some(Schema::read_from(&*value)?)), None => Ok(None), } } fn data_index(&self) -> Result> { match self.deref().get(b"data-index")? { Some(value) => Ok(bincode::deserialize(&value)?), None => Ok(PositiveBlob::default()), } } fn get_documents(&self, ids: &[DocumentId]) -> Result, Box> { if ids.is_empty() { return Ok(Vec::new()) } let schema = match self.schema()? { Some(schema) => schema, None => return Err(String::from("BUG: could not find schema").into()), }; unimplemented!() } }