fix: Make the examples build

This commit is contained in:
Clément Renault
2019-04-22 15:26:43 +02:00
parent ed6b6038ee
commit 7dbf5d6319
6 changed files with 51 additions and 42 deletions

View File

@ -16,7 +16,7 @@ ordered-float = { version = "1.0.2", features = ["serde"] }
sdset = "0.3.1"
serde = { version = "1.0.90", features = ["derive"] }
serde_json = { version = "1.0.39", features = ["preserve_order"] }
sled = "0.22.1"
sled = "0.23.0"
toml = { version = "0.5.0", features = ["preserve_order"] }
[dependencies.rmp-serde]

View File

@ -3,6 +3,7 @@ use std::io::{self, Cursor, BufRead};
use std::iter::FromIterator;
use std::path::Path;
use std::sync::Arc;
use std::{error, fmt};
use arc_swap::{ArcSwap, Lease};
use byteorder::{ReadBytesExt, BigEndian};
@ -50,6 +51,23 @@ impl From<SerializerError> for Error {
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
match self {
SchemaDiffer => write!(f, "schemas differ"),
SchemaMissing => write!(f, "this index does not have a schema"),
WordIndexMissing => write!(f, "this index does not have a word index"),
MissingDocumentId => write!(f, "document id is missing"),
SledError(e) => write!(f, "sled error; {}", e),
BincodeError(e) => write!(f, "bincode error; {}", e),
SerializerError(e) => write!(f, "serializer error; {}", e),
}
}
}
impl error::Error for Error { }
fn index_name(name: &str) -> Vec<u8> {
format!("index-{}", name).into_bytes()
}
@ -96,13 +114,6 @@ fn extract_document_key(key: Vec<u8>) -> io::Result<(DocumentId, SchemaAttr)> {
Ok((document_id, schema_attr))
}
fn ivec_into_arc(ivec: IVec) -> Arc<[u8]> {
match ivec {
IVec::Inline(len, bytes) => Arc::from(&bytes[..len as usize]),
IVec::Remote { buf } => buf,
}
}
#[derive(Clone)]
pub struct Database {
opened: Arc<ArcSwap<HashMap<String, RawIndex>>>,
@ -185,7 +196,7 @@ impl RawIndex {
let bytes = bytes.ok_or(Error::WordIndexMissing)?;
let word_index = {
let len = bytes.len();
let bytes = ivec_into_arc(bytes);
let bytes: Arc<[u8]> = Into::into(bytes);
let mut cursor = SharedDataCursor::from_shared_bytes(bytes, 0, len);
// TODO must handle this error
@ -399,7 +410,6 @@ impl DocumentsAddition {
Ok(())
}
pub fn finalize(self) -> sled::Result<()> {
let delta_index = self.indexer.build();

View File

@ -237,7 +237,7 @@ impl<'a> ser::SerializeSeq for SeqIndexer<'a> {
Ok(())
}
fn end(mut self) -> Result<Self::Ok, Self::Error> {
fn end(self) -> Result<Self::Ok, Self::Error> {
let texts = self.texts.iter().map(String::as_str);
self.indexer.index_text_seq(self.document_id, self.attribute, texts);
Ok(())