Keep Record impl near user

This commit is contained in:
2019-10-30 17:01:52 +01:00
parent 3b34991e24
commit cdb3746a34
2 changed files with 7 additions and 38 deletions

View File

@@ -2,11 +2,9 @@ use super::space::Position;
use super::space::Shape;
use super::space::Space;
use super::space_db::SpaceDB;
use super::space_index::SpaceFields;
use super::space_index::SpaceSetObject;
use super::DataBase;
use super::ResultSet;
use crate::SpaceObject;
pub struct CoreQueryParameters<'a> {
pub db: &'a DataBase,
@@ -67,16 +65,6 @@ impl Properties {
}
}
// FIXME: Which is faster, the code below or the automatically generated
// implementation?
/*
impl PartialEq for Properties {
fn eq(&self, other: &Self) -> bool {
self.id() == other.id() && self.type_name() == other.type_name()
}
}
*/
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Core {
title: String,
@@ -159,24 +147,6 @@ impl Core {
&self.properties
}
fn to_space_object(
&self,
space_id: &str,
list: Vec<(Position, SpaceFields)>,
) -> Vec<SpaceObject> {
list.into_iter()
.map(|(position, fields)| {
let offset: usize = fields.value().into();
let value = self.properties[offset].clone();
SpaceObject {
space_id: space_id.to_string(),
position: position.clone(),
value,
}
})
.collect()
}
fn decode_positions(
list: &mut [(Position, &Properties)],
space: &Space,
@@ -430,9 +400,3 @@ impl Core {
Ok(results)
}
}
impl ironsea_index::Record<String> for Core {
fn key(&self) -> String {
self.title.clone()
}
}

View File

@@ -29,7 +29,6 @@ pub struct SpaceObject {
pub value: Properties,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DataBase {
reference_spaces: ReferenceSpaceIndex,
cores: CoreIndex,
@@ -85,7 +84,7 @@ impl DataBase {
}
}
pub fn load_core(name: &str) -> Result<(Vec<Space>, Core), String> {
fn load_core(name: &str) -> Result<(Vec<Space>, Core), String> {
let mmap = DataBase::mmap_file(&name)?;
match bincode::deserialize(&mmap[..]) {
@@ -181,3 +180,9 @@ impl ironsea_index::Record<String> for Space {
self.name().clone()
}
}
impl ironsea_index::Record<String> for Core {
fn key(&self) -> String {
self.name().clone()
}
}