diff --git a/meilidb-core/src/data/mod.rs b/meilidb-core/src/data/mod.rs deleted file mode 100644 index cb708088d..000000000 --- a/meilidb-core/src/data/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod shared_data; - -pub use self::shared_data::SharedData; diff --git a/meilidb-core/src/data/shared_data.rs b/meilidb-core/src/data/shared_data.rs deleted file mode 100644 index fd505c6d9..000000000 --- a/meilidb-core/src/data/shared_data.rs +++ /dev/null @@ -1,58 +0,0 @@ -use std::sync::Arc; -use std::ops::Deref; - -#[derive(Clone)] -pub struct SharedData { - pub bytes: Arc<[u8]>, - pub offset: usize, - pub len: usize, -} - -impl SharedData { - pub fn from_bytes(vec: Vec) -> SharedData { - let len = vec.len(); - let bytes = Arc::from(vec); - SharedData::new(bytes, 0, len) - } - - pub fn new(bytes: Arc<[u8]>, offset: usize, len: usize) -> SharedData { - SharedData { bytes, offset, len } - } - - pub fn as_slice(&self) -> &[u8] { - &self.bytes[self.offset..self.offset + self.len] - } - - pub fn range(&self, offset: usize, len: usize) -> SharedData { - assert!(offset + len <= self.len); - SharedData { - bytes: self.bytes.clone(), - offset: self.offset + offset, - len: len, - } - } -} - -impl Default for SharedData { - fn default() -> SharedData { - SharedData { - bytes: Arc::from(Vec::new()), - offset: 0, - len: 0, - } - } -} - -impl Deref for SharedData { - type Target = [u8]; - - fn deref(&self) -> &Self::Target { - self.as_slice() - } -} - -impl AsRef<[u8]> for SharedData { - fn as_ref(&self) -> &[u8] { - self.as_slice() - } -} diff --git a/meilidb-core/src/lib.rs b/meilidb-core/src/lib.rs index 5bff103cd..6d527e381 100644 --- a/meilidb-core/src/lib.rs +++ b/meilidb-core/src/lib.rs @@ -1,11 +1,9 @@ pub mod criterion; -pub mod data; mod index; mod automaton; mod query_builder; mod distinct_map; -pub mod shared_data_cursor; pub mod write_to_bytes; use std::sync::Arc; diff --git a/meilidb-core/src/shared_data_cursor.rs b/meilidb-core/src/shared_data_cursor.rs deleted file mode 100644 index 9eeac472f..000000000 --- a/meilidb-core/src/shared_data_cursor.rs +++ /dev/null @@ -1,56 +0,0 @@ -use std::io::{self, Read, Cursor, BufRead}; -use std::sync::Arc; -use crate::data::SharedData; - -pub struct SharedDataCursor(Cursor); - -impl SharedDataCursor { - pub fn from_bytes(bytes: Vec) -> SharedDataCursor { - let len = bytes.len(); - let bytes = Arc::from(bytes); - - SharedDataCursor::from_shared_bytes(bytes, 0, len) - } - - pub fn from_shared_bytes(bytes: Arc<[u8]>, offset: usize, len: usize) -> SharedDataCursor { - let data = SharedData::new(bytes, offset, len); - let cursor = Cursor::new(data); - - SharedDataCursor(cursor) - } - - pub fn extract(&mut self, amt: usize) -> SharedData { - let offset = self.0.position() as usize; - let extracted = self.0.get_ref().range(offset, amt); - self.0.consume(amt); - - extracted - } -} - -impl Read for SharedDataCursor { - fn read(&mut self, buf: &mut [u8]) -> io::Result { - self.0.read(buf) - } -} - -impl BufRead for SharedDataCursor { - fn fill_buf(&mut self) -> io::Result<&[u8]> { - self.0.fill_buf() - } - - fn consume(&mut self, amt: usize) { - self.0.consume(amt) - } -} - -pub trait FromSharedDataCursor: Sized { - type Error; - - fn from_shared_data_cursor(cursor: &mut SharedDataCursor) -> Result; - - fn from_bytes(bytes: Vec) -> Result { - let mut cursor = SharedDataCursor::from_bytes(bytes); - Self::from_shared_data_cursor(&mut cursor) - } -}