feat: Introduce the meilidb-data workspace member

This commit is contained in:
Clément Renault 2019-03-29 17:01:10 +01:00
parent 77405cc103
commit 287d5dee4d
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE
4 changed files with 33 additions and 0 deletions

View File

@ -2,6 +2,7 @@
members = [
"meilidb",
"meilidb-core",
"meilidb-data",
"meilidb-tokenizer",
]

8
meilidb-data/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "meilidb-data"
version = "0.1.0"
authors = ["Kerollmops <renault.cle@gmail.com>"]
edition = "2018"
[dependencies]
sled = "0.20.0"

View File

@ -0,0 +1,21 @@
use std::path::Path;
use std::sync::Arc;
#[derive(Clone)]
pub struct Database(sled::Db);
impl Database {
pub fn start_default<P: AsRef<Path>>(path: P) -> sled::Result<Database> {
sled::Db::start_default(path).map(Database)
}
pub fn open_index(&self, name: &str) -> sled::Result<Index> {
let name = format!("index-{}", name);
let bytes = name.into_bytes();
self.0.open_tree(bytes).map(Index)
}
}
#[derive(Debug, Clone)]
pub struct Index(Arc<sled::Tree>);

3
meilidb-data/src/lib.rs Normal file
View File

@ -0,0 +1,3 @@
mod database;
pub use self::database::{Database, Index};