From 72a9b302f96db10b505f80b41eddfa85aed44ec4 Mon Sep 17 00:00:00 2001 From: Thom Date: Tue, 26 Jun 2018 16:34:18 -0700 Subject: [PATCH] Rename or delete things so that there is only one type named Entid (#768) * Delete the (apparently unused) EntId * Rename edn's Entid to EntidOrIdent to avoid confusion with the Entid that's actually an i64 * Fix travis beta bustage (This is actually unrelated to entids, but is a trivial fix nonetheless) --- db/src/debug.rs | 20 ++++++++++---------- db/src/internal_types.rs | 8 ++++---- db/src/tx.rs | 22 +++++++++++----------- edn/src/edn.rustpeg | 18 +++++++++--------- edn/src/entities.rs | 18 +++++++++--------- edn/src/pretty_print.rs | 2 +- src/ident.rs | 25 ------------------------- src/lib.rs | 1 - 8 files changed, 44 insertions(+), 70 deletions(-) delete mode 100644 src/ident.rs diff --git a/db/src/debug.rs b/db/src/debug.rs index a8e330b9..664c2460 100644 --- a/db/src/debug.rs +++ b/db/src/debug.rs @@ -32,7 +32,7 @@ use mentat_core::{ ValueType, }; use edn::entities::{ - Entid, + EntidOrIdent, }; use schema::{ SchemaBuilding, @@ -43,8 +43,8 @@ use types::Schema; #[derive(Clone,Debug,Eq,Hash,Ord,PartialOrd,PartialEq)] pub(crate) struct Datom { // TODO: generalize this. - e: Entid, - a: Entid, + e: EntidOrIdent, + a: EntidOrIdent, v: edn::Value, tx: i64, added: Option, @@ -70,10 +70,10 @@ pub(crate) struct FulltextValues(pub Vec<(i64, String)>); impl Datom { pub(crate) fn into_edn(&self) -> edn::Value { - let f = |entid: &Entid| -> edn::Value { + let f = |entid: &EntidOrIdent| -> edn::Value { match *entid { - Entid::Entid(ref y) => edn::Value::Integer(y.clone()), - Entid::Ident(ref y) => edn::Value::Keyword(y.clone()), + EntidOrIdent::Entid(ref y) => edn::Value::Integer(y.clone()), + EntidOrIdent::Ident(ref y) => edn::Value::Keyword(y.clone()), } }; @@ -121,8 +121,8 @@ impl ToIdent for TypedValue { } /// Convert a numeric entid to an ident `Entid` if possible, otherwise a numeric `Entid`. -fn to_entid(schema: &Schema, entid: i64) -> Entid { - schema.get_ident(entid).map_or(Entid::Entid(entid), |ident| Entid::Ident(ident.clone())) +fn to_entid(schema: &Schema, entid: i64) -> EntidOrIdent { + schema.get_ident(entid).map_or(EntidOrIdent::Entid(entid), |ident| EntidOrIdent::Ident(ident.clone())) } /// Return the set of datoms in the store, ordered by (e, a, v, tx), but not including any datoms of @@ -160,7 +160,7 @@ pub(crate) fn datoms_after>(conn: &rusqlite::Connection, schem let tx: i64 = row.get_checked(4)?; Ok(Some(Datom { - e: Entid::Entid(e), + e: EntidOrIdent::Entid(e), a: to_entid(borrowed_schema, a), v: value, tx: tx, @@ -197,7 +197,7 @@ pub(crate) fn transactions_after>(conn: &rusqlite::Connection, let added: bool = row.get_checked(5)?; Ok(Datom { - e: Entid::Entid(e), + e: EntidOrIdent::Entid(e), a: to_entid(borrowed_schema, a), v: value, tx: tx, diff --git a/db/src/internal_types.rs b/db/src/internal_types.rs index b61add26..6ccbd4cd 100644 --- a/db/src/internal_types.rs +++ b/db/src/internal_types.rs @@ -63,10 +63,10 @@ impl TransactableValue for ValueAndSpan { fn into_entity_place(self) -> Result> { use self::SpannedValue::*; match self.inner { - Integer(v) => Ok(EntityPlace::Entid(entities::Entid::Entid(v))), + Integer(v) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Entid(v))), Keyword(v) => { if v.is_namespaced() { - Ok(EntityPlace::Entid(entities::Entid::Ident(v))) + Ok(EntityPlace::Entid(entities::EntidOrIdent::Ident(v))) } else { // We only allow namespaced idents. bail!(DbError::InputError(errors::InputError::BadEntityPlace)) @@ -121,8 +121,8 @@ impl TransactableValue for TypedValue { fn into_entity_place(self) -> Result> { match self { - TypedValue::Ref(x) => Ok(EntityPlace::Entid(entities::Entid::Entid(x))), - TypedValue::Keyword(x) => Ok(EntityPlace::Entid(entities::Entid::Ident((*x).clone()))), + TypedValue::Ref(x) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Entid(x))), + TypedValue::Keyword(x) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Ident((*x).clone()))), TypedValue::String(x) => Ok(EntityPlace::TempId(TempId::External((*x).clone()))), TypedValue::Boolean(_) | TypedValue::Long(_) | diff --git a/db/src/tx.rs b/db/src/tx.rs index ad7f1746..ab48bb0c 100644 --- a/db/src/tx.rs +++ b/db/src/tx.rs @@ -168,7 +168,7 @@ pub struct Tx<'conn, 'a, W> where W: TransactWatcher { /// something suitable for the entity position rather than something suitable for a value position. pub fn remove_db_id(map: &mut entmod::MapNotation) -> Result>> { // TODO: extract lazy defined constant. - let db_id_key = entmod::Entid::Ident(Keyword::namespaced("db", "id")); + let db_id_key = entmod::EntidOrIdent::Ident(Keyword::namespaced("db", "id")); let db_id: Option> = if let Some(id) = map.remove(&db_id_key) { match id { @@ -291,8 +291,8 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher { fn intern_lookup_ref(&mut self, lookup_ref: &entmod::LookupRef) -> Result { let lr_a: i64 = match lookup_ref.a { - AttributePlace::Entid(entmod::Entid::Entid(ref a)) => *a, - AttributePlace::Entid(entmod::Entid::Ident(ref a)) => self.schema.require_entid(&a)?.into(), + AttributePlace::Entid(entmod::EntidOrIdent::Entid(ref a)) => *a, + AttributePlace::Entid(entmod::EntidOrIdent::Ident(ref a)) => self.schema.require_entid(&a)?.into(), }; let lr_attribute: &Attribute = self.schema.require_attribute_for_entid(lr_a)?; @@ -319,8 +319,8 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher { match x { entmod::EntityPlace::Entid(e) => { let e = match e { - entmod::Entid::Entid(ref e) => self.ensure_entid_exists(*e)?, - entmod::Entid::Ident(ref e) => self.ensure_ident_exists(&e)?, + entmod::EntidOrIdent::Entid(ref e) => self.ensure_entid_exists(*e)?, + entmod::EntidOrIdent::Ident(ref e) => self.ensure_ident_exists(&e)?, }; Ok(Either::Left(e)) }, @@ -342,10 +342,10 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher { } } - fn entity_a_into_term_a(&mut self, x: entmod::Entid) -> Result { + fn entity_a_into_term_a(&mut self, x: entmod::EntidOrIdent) -> Result { let a = match x { - entmod::Entid::Entid(ref a) => *a, - entmod::Entid::Ident(ref a) => self.schema.require_entid(&a)?.into(), + entmod::EntidOrIdent::Entid(ref a) => *a, + entmod::EntidOrIdent::Ident(ref a) => self.schema.require_entid(&a)?.into(), }; Ok(a) } @@ -354,7 +354,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher { self.entity_e_into_term_e(x).map(|r| r.map_left(|ke| TypedValue::Ref(ke.0))) } - fn entity_v_into_term_e(&mut self, x: entmod::ValuePlace, backward_a: &entmod::Entid) -> Result> { + fn entity_v_into_term_e(&mut self, x: entmod::ValuePlace, backward_a: &entmod::EntidOrIdent) -> Result> { match backward_a.unreversed() { None => { bail!(DbError::NotYetImplemented(format!("Cannot explode map notation value in :attr/_reversed notation for forward attribute"))); @@ -510,7 +510,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher { deque.push_front(Entity::AddOrRetract { op: op.clone(), e: e.clone(), - a: AttributePlace::Entid(entmod::Entid::Entid(a)), + a: AttributePlace::Entid(entmod::EntidOrIdent::Entid(a)), v: vv, }); } @@ -573,7 +573,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher { deque.push_front(Entity::AddOrRetract { op: OpType::Add, e: db_id.clone(), - a: AttributePlace::Entid(entmod::Entid::Entid(inner_a)), + a: AttributePlace::Entid(entmod::EntidOrIdent::Entid(inner_a)), v: inner_v, }); } diff --git a/edn/src/edn.rustpeg b/edn/src/edn.rustpeg index 48759f07..21926b1f 100644 --- a/edn/src/edn.rustpeg +++ b/edn/src/edn.rustpeg @@ -238,18 +238,18 @@ raw_forward_namespaced_keyword -> Keyword raw_backward_namespaced_keyword -> Keyword = v:raw_namespaced_keyword {? if v.is_backward() { Ok(v) } else { Err("expected namespaced :backward/_keyword") } } -entid -> Entid - = v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { Entid::Entid(v) } - / v:raw_namespaced_keyword { Entid::Ident(v) } +entid -> EntidOrIdent + = v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { EntidOrIdent::Entid(v) } + / v:raw_namespaced_keyword { EntidOrIdent::Ident(v) } / #expected("entid") -forward_entid -> Entid - = v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { Entid::Entid(v) } - / v:raw_forward_namespaced_keyword { Entid::Ident(v) } +forward_entid -> EntidOrIdent + = v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { EntidOrIdent::Entid(v) } + / v:raw_forward_namespaced_keyword { EntidOrIdent::Ident(v) } / #expected("forward entid") -backward_entid -> Entid - = v:raw_backward_namespaced_keyword { Entid::Ident(v.to_reversed()) } +backward_entid -> EntidOrIdent + = v:raw_backward_namespaced_keyword { EntidOrIdent::Ident(v.to_reversed()) } / #expected("backward entid") lookup_ref -> LookupRef @@ -265,7 +265,7 @@ entity_place -> EntityPlace / v:lookup_ref { EntityPlace::LookupRef(v) } / v:tx_function { EntityPlace::TxFunction(v) } -value_place_pair -> (Entid, ValuePlace) +value_place_pair -> (EntidOrIdent, ValuePlace) = k:(entid) __ v:(value_place) { (k, v) } map_notation -> MapNotation diff --git a/edn/src/entities.rs b/edn/src/entities.rs index eee3985a..17610e20 100644 --- a/edn/src/entities.rs +++ b/edn/src/entities.rs @@ -45,16 +45,16 @@ impl fmt::Display for TempId { } #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] -pub enum Entid { +pub enum EntidOrIdent { Entid(i64), Ident(Keyword), } -impl Entid { - pub fn unreversed(&self) -> Option { +impl EntidOrIdent { + pub fn unreversed(&self) -> Option { match self { - &Entid::Entid(_) => None, - &Entid::Ident(ref a) => a.unreversed().map(Entid::Ident), + &EntidOrIdent::Entid(_) => None, + &EntidOrIdent::Ident(ref a) => a.unreversed().map(EntidOrIdent::Ident), } } } @@ -84,13 +84,13 @@ pub struct TxFunction { pub op: PlainSymbol, } -pub type MapNotation = BTreeMap>; +pub type MapNotation = BTreeMap>; #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] pub enum ValuePlace { // We never know at parse-time whether an integer or ident is really an entid, but we will often // know when building entities programmatically. - Entid(Entid), + Entid(EntidOrIdent), // We never know at parse-time whether a string is really a tempid, but we will often know when // building entities programmatically. TempId(TempId), @@ -103,7 +103,7 @@ pub enum ValuePlace { #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] pub enum EntityPlace { - Entid(Entid), + Entid(EntidOrIdent), TempId(TempId), LookupRef(LookupRef), TxFunction(TxFunction), @@ -111,7 +111,7 @@ pub enum EntityPlace { #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] pub enum AttributePlace { - Entid(Entid), + Entid(EntidOrIdent), } #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] diff --git a/edn/src/pretty_print.rs b/edn/src/pretty_print.rs index 8c579a48..b7a73cae 100644 --- a/edn/src/pretty_print.rs +++ b/edn/src/pretty_print.rs @@ -71,7 +71,7 @@ impl Value { Value::NamespacedSymbol(ref v) => pp.text(v.namespace()).append("/").append(v.name()), Value::PlainSymbol(ref v) => pp.text(v.to_string()), Value::Keyword(ref v) => pp.text(v.to_string()), - Value::Text(ref v) => pp.text("\"").append(v.as_ref()).append("\""), + Value::Text(ref v) => pp.text("\"").append(v.as_str()).append("\""), Value::Uuid(ref u) => pp.text("#uuid \"").append(u.hyphenated().to_string()).append("\""), Value::Instant(ref v) => pp.text("#inst \"").append(v.to_rfc3339_opts(SecondsFormat::AutoSi, true)).append("\""), _ => pp.text(self.to_string()) diff --git a/src/ident.rs b/src/ident.rs deleted file mode 100644 index cc234275..00000000 --- a/src/ident.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2016 Mozilla -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the -// specific language governing permissions and limitations under the License. - -extern crate edn; - -use edn::symbols::Keyword; - -pub type EntId = u32; // TODO: u64? Not all DB values will be representable in a u32. - -/// The ability to transform entity identifiers (entids) into keyword names (idents). -pub trait ToIdent { - fn ident(&self, entid: EntId) -> Option; -} - -/// The ability to transform idents into the corresponding entid. -pub trait ToEntId { - fn entid(&self, ident: &Keyword) -> Option; -} diff --git a/src/lib.rs b/src/lib.rs index b3a657e5..c62f3af8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,7 +106,6 @@ macro_rules! kw { pub mod errors; pub mod conn; pub mod entity_builder; -pub mod ident; pub mod query; pub mod query_builder; pub mod store;