diff --git a/core/src/util.rs b/core/src/util.rs index 5f3f7321..77d02735 100644 --- a/core/src/util.rs +++ b/core/src/util.rs @@ -56,4 +56,33 @@ impl OptionEffect for Option { } self } -} \ No newline at end of file +} + +#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] +pub enum Either { + Left(L), + Right(R), +} + +// Cribbed from https://github.com/bluss/either/blob/f793721f3fdeb694f009e731b23a2858286bc0d6/src/lib.rs#L219-L259. +impl Either { + pub fn map_left(self, f: F) -> Either + where F: FnOnce(L) -> M + { + use self::Either::*; + match self { + Left(l) => Left(f(l)), + Right(r) => Right(r), + } + } + + pub fn map_right(self, f: F) -> Either + where F: FnOnce(R) -> S + { + use self::Either::*; + match self { + Left(l) => Left(l), + Right(r) => Right(f(r)), + } + } +} diff --git a/db/src/internal_types.rs b/db/src/internal_types.rs index f97f1b0a..2955faf1 100644 --- a/db/src/internal_types.rs +++ b/db/src/internal_types.rs @@ -15,6 +15,8 @@ use std::collections::HashMap; use std::rc::Rc; +use mentat_core::util::Either; + use errors; use errors::ErrorKind; use types::{ @@ -33,33 +35,6 @@ pub enum Term { AddOrRetract(OpType, E, Entid, V), } -#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] -pub enum Either { - Left(L), - Right(R), -} - -// Cribbed from https://github.com/bluss/either/blob/f793721f3fdeb694f009e731b23a2858286bc0d6/src/lib.rs#L219-L259. -impl Either { - pub fn map_left(self, f: F) -> Either - where F: FnOnce(L) -> M - { - match self { - Left(l) => Left(f(l)), - Right(r) => Right(r), - } - } - - pub fn map_right(self, f: F) -> Either - where F: FnOnce(R) -> S - { - match self { - Left(l) => Left(l), - Right(r) => Right(f(r)), - } - } -} - use self::Either::*; /// An entid that's either already in the store, or newly allocated to a tempid. diff --git a/db/src/tx.rs b/db/src/tx.rs index 9ad0f496..50cb2c56 100644 --- a/db/src/tx.rs +++ b/db/src/tx.rs @@ -64,7 +64,6 @@ use edn::{ use entids; use errors::{ErrorKind, Result}; use internal_types::{ - Either, KnownEntid, KnownEntidOr, LookupRef, @@ -76,7 +75,10 @@ use internal_types::{ TermWithTempIdsAndLookupRefs, TermWithoutTempIds, TypedValueOr, - replace_lookup_ref}; + replace_lookup_ref, +}; + +use mentat_core::util::Either; use mentat_core::{ DateTime, diff --git a/db/src/upsert_resolution.rs b/db/src/upsert_resolution.rs index 03cbf971..3c74562f 100644 --- a/db/src/upsert_resolution.rs +++ b/db/src/upsert_resolution.rs @@ -28,7 +28,9 @@ use internal_types::{ TermWithoutTempIds, TermWithTempIds, }; -use internal_types::Either::*; + +use mentat_core::util::Either::*; + use mentat_core::{ attribute, Attribute,