Pre: Move Entid and KnownEntid into core_traits

This commit is contained in:
Grisha Kruglov 2018-08-08 10:35:06 -07:00 committed by Grisha Kruglov
parent f8478835a2
commit a57ba5d79f
60 changed files with 284 additions and 91 deletions

View file

@ -43,6 +43,9 @@ features = ["limits"]
[dependencies.edn]
path = "edn"
[dependencies.core_traits]
path = "core-traits"
[dependencies.mentat_core]
path = "core"

11
core-traits/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "core_traits"
version = "0.0.1"
workspace = ".."
[lib]
name = "core_traits"
path = "lib.rs"
[dependencies.edn]
path = "../edn"

55
core-traits/lib.rs Normal file
View file

@ -0,0 +1,55 @@
// Copyright 2018 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::entities::{
AttributePlace,
EntityPlace,
EntidOrIdent,
ValuePlace,
TransactableValueMarker,
};
/// Represents one entid in the entid space.
///
/// Per https://www.sqlite.org/datatype3.html (see also http://stackoverflow.com/a/8499544), SQLite
/// stores signed integers up to 64 bits in size. Since u32 is not appropriate for our use case, we
/// use i64 rather than manually truncating u64 to u63 and casting to i64 throughout the codebase.
pub type Entid = i64;
/// An entid that's either already in the store, or newly allocated to a tempid.
/// TODO: we'd like to link this in some way to the lifetime of a particular PartitionMap.
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct KnownEntid(pub Entid);
impl From<KnownEntid> for Entid {
fn from(k: KnownEntid) -> Entid {
k.0
}
}
impl<V: TransactableValueMarker> Into<EntityPlace<V>> for KnownEntid {
fn into(self) -> EntityPlace<V> {
EntityPlace::Entid(EntidOrIdent::Entid(self.0))
}
}
impl Into<AttributePlace> for KnownEntid {
fn into(self) -> AttributePlace {
AttributePlace::Entid(EntidOrIdent::Entid(self.0))
}
}
impl<V: TransactableValueMarker> Into<ValuePlace<V>> for KnownEntid {
fn into(self) -> ValuePlace<V> {
ValuePlace::Entid(EntidOrIdent::Entid(self.0))
}
}

View file

@ -14,6 +14,9 @@ uuid = { version = "0.5", features = ["v4", "serde"] }
serde = { version = "1.0", features = ["rc"] }
serde_derive = "1.0"
[dependencies.core_traits]
path = "../core-traits"
[dependencies.edn]
path = "../edn"
features = ["serde_support"]

View file

@ -14,8 +14,11 @@ use std::collections::{
BTreeSet,
};
use ::{
use core_traits::{
Entid,
};
use ::{
Schema,
TypedValue,
};

View file

@ -16,6 +16,8 @@ extern crate ordered_float;
extern crate uuid;
extern crate serde;
extern crate core_traits;
#[macro_use]
extern crate lazy_static;
@ -24,6 +26,11 @@ extern crate serde_derive;
extern crate edn;
use core_traits::{
Entid,
KnownEntid,
};
pub mod values;
mod cache;
@ -70,8 +77,6 @@ pub use tx_report::{
pub use types::{
Binding,
Entid,
KnownEntid,
StructuredMap,
TypedValue,
ValueType,

View file

@ -14,9 +14,12 @@ use std::collections::{
BTreeMap,
};
use core_traits::{
Entid,
};
use ::{
DateTime,
Entid,
Utc,
};

View file

@ -57,32 +57,15 @@ use ::edn::{
};
use ::edn::entities::{
AttributePlace,
EntidOrIdent,
EntityPlace,
ValuePlace,
TransactableValueMarker,
};
use values;
/// Represents one entid in the entid space.
///
/// Per https://www.sqlite.org/datatype3.html (see also http://stackoverflow.com/a/8499544), SQLite
/// stores signed integers up to 64 bits in size. Since u32 is not appropriate for our use case, we
/// use i64 rather than manually truncating u64 to u63 and casting to i64 throughout the codebase.
pub type Entid = i64;
/// An entid that's either already in the store, or newly allocated to a tempid.
/// TODO: we'd like to link this in some way to the lifetime of a particular PartitionMap.
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct KnownEntid(pub Entid);
impl From<KnownEntid> for Entid {
fn from(k: KnownEntid) -> Entid {
k.0
}
}
use core_traits::{
Entid,
KnownEntid,
};
impl From<KnownEntid> for TypedValue {
fn from(k: KnownEntid) -> TypedValue {
@ -90,24 +73,6 @@ impl From<KnownEntid> for TypedValue {
}
}
impl<V: TransactableValueMarker> Into<EntityPlace<V>> for KnownEntid {
fn into(self) -> EntityPlace<V> {
EntityPlace::Entid(EntidOrIdent::Entid(self.0))
}
}
impl Into<AttributePlace> for KnownEntid {
fn into(self) -> AttributePlace {
AttributePlace::Entid(EntidOrIdent::Entid(self.0))
}
}
impl<V: TransactableValueMarker> Into<ValuePlace<V>> for KnownEntid {
fn into(self) -> ValuePlace<V> {
ValuePlace::Entid(EntidOrIdent::Entid(self.0))
}
}
/// The attribute of each Mentat assertion has a :db/valueType constraining the value to a
/// particular set. Mentat recognizes the following :db/valueType values.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]

View file

@ -32,6 +32,9 @@ path = "../edn"
[dependencies.mentat_core]
path = "../core"
[dependencies.core_traits]
path = "../core-traits"
[dependencies.mentat_sql]
path = "../sql"

View file

@ -78,10 +78,13 @@ use failure::{
use rusqlite;
use core_traits::{
Entid,
};
use mentat_core::{
Binding,
CachedAttributes,
Entid,
HasSchema,
Schema,
TypedValue,

View file

@ -40,11 +40,15 @@ use edn::{
};
use entids;
use core_traits::{
Entid,
};
use mentat_core::{
attribute,
Attribute,
AttributeBitFlags,
Entid,
FromMicros,
IdentMap,
Schema,
@ -1221,10 +1225,12 @@ mod tests {
use edn::entities::{
OpType,
};
use core_traits::{
KnownEntid,
};
use mentat_core::{
HasSchema,
Keyword,
KnownEntid,
attribute,
};
use mentat_core::util::Either::*;

View file

@ -66,6 +66,11 @@ use db::{read_attribute_map,read_ident_map};
use edn;
use entids;
use errors::Result;
use core_traits::{
Entid,
};
use mentat_core::{
HasSchema,
SQLValueType,

View file

@ -14,7 +14,9 @@
///
/// Used through-out the transactor to match core DB constructs.
use types::{Entid};
use core_traits::{
Entid,
};
// Added in SQL schema v1.
pub const DB_IDENT: Entid = 1;

View file

@ -26,11 +26,13 @@ use rusqlite;
use edn::entities::{
TempId,
};
use mentat_core::{
use core_traits::{
Entid,
KnownEntid,
};
use types::{
Entid,
TypedValue,
ValueType,
};

View file

@ -18,7 +18,10 @@ use std::collections::{
HashMap,
};
use mentat_core::KnownEntid;
use core_traits::{
Entid,
KnownEntid,
};
use mentat_core::util::Either;
@ -48,7 +51,6 @@ use types::{
Attribute,
AVMap,
AVPair,
Entid,
Schema,
TransactableValue,
TypedValue,

View file

@ -25,6 +25,7 @@ extern crate time;
#[macro_use] extern crate edn;
#[macro_use] extern crate mentat_core;
extern crate core_traits;
extern crate mentat_sql;
use std::iter::repeat;

View file

@ -38,9 +38,13 @@ use errors::{
DbErrorKind,
Result,
};
use core_traits::{
Entid,
};
use mentat_core::{
attribute,
Entid,
Schema,
AttributeMap,
TypedValue,

View file

@ -17,14 +17,18 @@ use errors::{
Result,
};
use edn::symbols;
use core_traits::{
Entid,
KnownEntid,
};
use mentat_core::{
attribute,
Attribute,
Entid,
EntidMap,
HasSchema,
IdentMap,
KnownEntid,
Schema,
AttributeMap,
TypedValue,

View file

@ -17,11 +17,14 @@ use errors::{
Result,
};
use mentat_core::{
use core_traits::{
Entid,
KnownEntid,
};
use mentat_core::{
Schema,
TypedValue,
KnownEntid,
};
use edn::{

View file

@ -89,9 +89,13 @@ use internal_types::{
use mentat_core::util::Either;
use core_traits::{
Entid,
KnownEntid,
};
use mentat_core::{
DateTime,
KnownEntid,
Schema,
TxReport,
Utc,
@ -116,7 +120,6 @@ use types::{
AVMap,
AVPair,
Attribute,
Entid,
PartitionMap,
TransactableValue,
TypedValue,

View file

@ -13,8 +13,11 @@ use std::collections::{
BTreeMap,
};
use mentat_core::{
use core_traits::{
Entid,
};
use mentat_core::{
TypedValue,
ValueType,
};

View file

@ -26,8 +26,11 @@ use indexmap::{
IndexMap,
};
use mentat_core::{
use core_traits::{
Entid,
};
use mentat_core::{
Schema,
TypedValue,
};

View file

@ -26,11 +26,14 @@ use std::ops::{
extern crate mentat_core;
use core_traits::{
Entid,
};
pub use self::mentat_core::{
Attribute,
AttributeBitFlags,
DateTime,
Entid,
Schema,
TypedValue,
Utc,

View file

@ -40,10 +40,13 @@ use internal_types::{
use mentat_core::util::Either::*;
use core_traits::{
Entid,
};
use mentat_core::{
attribute,
Attribute,
Entid,
Schema,
TypedValue,
};

View file

@ -17,8 +17,11 @@
// - When observers are registered we want to flip some flags as writes occur so that we can
// notifying them outside the transaction.
use mentat_core::{
use core_traits::{
Entid,
};
use mentat_core::{
Schema,
TypedValue,
};

View file

@ -10,6 +10,9 @@ failure_derive = "0.1.1"
[dependencies.mentat_core]
path = "../core"
[dependencies.core_traits]
path = "../core-traits"
[dependencies.mentat_query]
path = "../query"

View file

@ -25,12 +25,15 @@ use std::fmt::{
Formatter,
};
use core_traits::{
Entid,
KnownEntid,
};
use mentat_core::{
Attribute,
Cloned,
Entid,
HasSchema,
KnownEntid,
Schema,
TypedValue,
ValueType,

View file

@ -8,9 +8,12 @@
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
use core_traits::{
Entid,
};
use mentat_core::{
Cloned,
Entid,
HasSchema,
TypedValue,
ValueType,

View file

@ -13,6 +13,7 @@ extern crate failure;
#[macro_use] extern crate failure_derive;
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_query;
use std::collections::BTreeSet;
@ -25,9 +26,12 @@ mod types;
mod validate;
mod clauses;
use core_traits::{
Entid,
};
use mentat_core::{
CachedAttributes,
Entid,
Schema,
TypedValue,
ValueType,

View file

@ -14,8 +14,11 @@ use std::fmt::{
Formatter,
};
use mentat_core::{
use core_traits::{
Entid,
};
use mentat_core::{
TypedValue,
ValueRc,
ValueType,

View file

@ -9,6 +9,7 @@
// specific language governing permissions and limitations under the License.
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_query;
extern crate mentat_query_algebrizer;

View file

@ -9,6 +9,7 @@
// specific language governing permissions and limitations under the License.
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_query;
extern crate mentat_query_algebrizer;

View file

@ -9,6 +9,7 @@
// specific language governing permissions and limitations under the License.
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_query;
extern crate mentat_query_algebrizer;

View file

@ -9,6 +9,7 @@
// specific language governing permissions and limitations under the License.
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_query;
extern crate mentat_query_algebrizer;

View file

@ -13,9 +13,12 @@
// this module will get warnings otherwise).
#![allow(dead_code)]
use core_traits::{
Entid,
};
use mentat_core::{
Attribute,
Entid,
Schema,
ValueType,
};

View file

@ -12,6 +12,9 @@ indexmap = "1"
version = "0.13"
features = ["limits"]
[dependencies.core_traits]
path = "../core-traits"
[dependencies.mentat_core]
path = "../core"

View file

@ -16,6 +16,7 @@ extern crate indexmap;
extern crate rusqlite;
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_db; // For value conversion.
extern crate mentat_query;
extern crate mentat_query_algebrizer;

View file

@ -18,7 +18,7 @@ use mentat_query_pull::{
Puller,
};
use mentat_core::{
use core_traits::{
Entid,
};

View file

@ -13,9 +13,12 @@ use std::collections::{
BTreeSet,
};
use core_traits::{
Entid,
};
use mentat_core::{
Binding,
Entid,
Schema,
StructuredMap,
TypedValue,

View file

@ -9,13 +9,17 @@
// specific language governing permissions and limitations under the License.
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_query;
extern crate mentat_query_algebrizer;
extern crate mentat_query_projector;
use core_traits::{
Entid,
};
use mentat_core::{
Attribute,
Entid,
Schema,
ValueType,
};

View file

@ -14,6 +14,9 @@ features = ["limits"]
[dependencies.mentat_core]
path = "../core"
[dependencies.core_traits]
path = "../core-traits"
[dependencies.mentat_db]
path = "../db"

View file

@ -14,7 +14,7 @@ use mentat_db::{
DbError,
};
use mentat_core::{
use core_traits::{
Entid,
};

View file

@ -65,6 +65,7 @@ extern crate failure_derive;
extern crate rusqlite;
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_db;
extern crate mentat_query;
extern crate mentat_query_algebrizer;
@ -80,10 +81,13 @@ use std::iter::{
once,
};
use core_traits::{
Entid,
};
use mentat_core::{
Binding,
Cloned,
Entid,
HasSchema,
Keyword,
Schema,

View file

@ -5,6 +5,9 @@ workspace = ".."
[dependencies]
[dependencies.core_traits]
path = "../core-traits"
[dependencies.mentat_core]
path = "../core"

View file

@ -9,13 +9,18 @@
// specific language governing permissions and limitations under the License.
#[macro_use] extern crate mentat_core;
extern crate core_traits;
extern crate mentat_query;
extern crate mentat_query_algebrizer;
extern crate mentat_sql;
use std::boxed::Box;
use mentat_core::{
use core_traits::{
Entid,
};
use mentat_core::{
SQLTypeAffinity,
TypedValue,
ValueType,

View file

@ -10,6 +10,9 @@ failure_derive = "0.1.1"
[dependencies.mentat_core]
path = "../core"
[dependencies.core_traits]
path = "../core-traits"
[dependencies.mentat_sql]
path = "../sql"

View file

@ -9,6 +9,7 @@
// specific language governing permissions and limitations under the License.
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_query;
extern crate mentat_query_algebrizer;
extern crate mentat_query_projector;
@ -25,9 +26,12 @@ use mentat_query::{
Variable,
};
use core_traits::{
Entid,
};
use mentat_core::{
Attribute,
Entid,
Schema,
TypedValue,
ValueType,

View file

@ -45,11 +45,14 @@ use edn::{
InternSet,
};
pub use core_traits::{
Entid,
KnownEntid,
};
use mentat_core::{
Attribute,
Entid,
HasSchema,
KnownEntid,
Keyword,
Schema,
StructuredMap,

View file

@ -23,6 +23,7 @@ extern crate uuid;
pub extern crate edn;
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_db;
extern crate mentat_query;
extern crate mentat_query_algebrizer;
@ -34,14 +35,17 @@ extern crate mentat_sql;
#[cfg(feature = "syncable")]
extern crate mentat_tolstoy;
pub use core_traits::{
Entid,
KnownEntid,
};
pub use mentat_core::{
Attribute,
Binding,
DateTime,
Entid,
HasSchema,
Keyword,
KnownEntid,
Schema,
StructuredMap,
TxReport,

View file

@ -13,11 +13,14 @@ use rusqlite::types::ToSql;
use std::rc::Rc;
use core_traits::{
Entid,
KnownEntid,
};
use mentat_core::{
Binding,
Entid,
HasSchema,
KnownEntid,
Schema,
TypedValue,
};

View file

@ -13,9 +13,12 @@ use std::collections::{
BTreeMap,
};
pub use core_traits::{
Entid,
};
use mentat_core::{
DateTime,
Entid,
Keyword,
Binding,
TypedValue,

View file

@ -26,8 +26,11 @@ use rusqlite;
use edn;
use mentat_core::{
use core_traits::{
Entid,
};
use mentat_core::{
Keyword,
StructuredMap,
TxReport,

View file

@ -99,7 +99,7 @@ use mentat_core::attribute::{
Unique,
};
use mentat_core::{
use core_traits::{
KnownEntid,
};

View file

@ -14,6 +14,7 @@ extern crate time;
#[macro_use]
extern crate mentat;
extern crate mentat_core;
extern crate core_traits;
extern crate mentat_db;
// TODO: when we switch to `failure`, make this more humane.
@ -25,11 +26,14 @@ use std::str::FromStr;
use chrono::FixedOffset;
use core_traits::{
Entid,
KnownEntid,
};
use mentat_core::{
DateTime,
Entid,
HasSchema,
KnownEntid,
Utc,
Uuid,
ValueType,

View file

@ -10,6 +10,7 @@
extern crate mentat;
extern crate mentat_core;
extern crate core_traits;
#[cfg(feature = "syncable")]
extern crate mentat_tolstoy;
@ -27,8 +28,10 @@ mod tests {
TxPart,
};
use mentat_tolstoy::errors::Result;
use mentat_core::{
use core_traits::{
Entid,
};
use mentat_core::{
TypedValue,
ValueType,
};

View file

@ -24,6 +24,9 @@ path = "../edn"
[dependencies.mentat_core]
path = "../core"
[dependencies.core_traits]
path = "../core-traits"
[dependencies.mentat_db]
path = "../db"

View file

@ -34,6 +34,7 @@ extern crate serde_json;
#[cfg_attr(test, macro_use)] extern crate mentat_db;
extern crate mentat_core;
extern crate core_traits;
extern crate rusqlite;
extern crate uuid;

View file

@ -25,7 +25,10 @@ use serde_json;
use tokio_core::reactor::Core;
use uuid::Uuid;
use mentat_core::Entid;
use core_traits::{
Entid,
};
use metadata::SyncMetadataClient;
use metadata::HeadTrackable;
use schema::ensure_current_version;

View file

@ -11,7 +11,10 @@
use std::collections::HashMap;
use rusqlite;
use uuid::Uuid;
use mentat_core::Entid;
use core_traits::{
Entid,
};
use errors::{
TolstoyError,

View file

@ -19,8 +19,11 @@ use mentat_db::{
TypedSQLValue,
};
use mentat_core::{
use core_traits::{
Entid,
};
use mentat_core::{
TypedValue,
};