From a5cda7c3e950a22bff946307915f18b2070fee54 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Tue, 3 Apr 2018 19:22:10 -0700 Subject: [PATCH] Allow passing a TermBuilder to be transacted by InProgress; add TermBuilder::is_empty. r=emily --- src/conn.rs | 10 ++++++++++ src/entity_builder.rs | 18 +++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/conn.rs b/src/conn.rs index 14626791..11415a35 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -83,6 +83,7 @@ use uuid::Uuid; use entity_builder::{ BuildTerms, InProgressBuilder, + TermBuilder, }; use errors::*; @@ -390,6 +391,15 @@ impl<'a, 'c> InProgress<'a, 'c> { self.use_caching = yesno; } + /// If you only have a reference to an `InProgress`, you can't use the easy builder. + /// This exists so you can make your own. + pub fn transact_builder(&mut self, builder: TermBuilder) -> Result { + builder.build() + .and_then(|(terms, tempid_set)| { + self.transact_terms(terms, tempid_set) + }) + } + pub fn transact_terms(&mut self, terms: I, tempid_set: InternSet) -> Result where I: IntoIterator { let w = InProgressTransactWatcher::new( &mut self.tx_observer_watcher, diff --git a/src/entity_builder.rs b/src/entity_builder.rs index 7f1ff23f..5cac5d34 100644 --- a/src/entity_builder.rs +++ b/src/entity_builder.rs @@ -161,6 +161,10 @@ impl TermBuilder { } } + pub fn is_empty(&self) -> bool { + self.terms.is_empty() + } + #[allow(dead_code)] pub fn numbered_tempid(&mut self, id: i64) -> TempIdHandle { self.tempids.intern(TempId::Internal(id)) @@ -213,15 +217,11 @@ impl<'a, 'c> InProgressBuilder<'a, 'c> { /// step fails, roll back. Return the `TxReport`. pub fn commit(self) -> Result { let mut in_progress = self.in_progress; - self.builder - .build() - .and_then(|(terms, tempid_set)| { - in_progress.transact_terms(terms, tempid_set) - .and_then(|report| { - in_progress.commit()?; - Ok(report) - }) - }) + in_progress.transact_builder(self.builder) + .and_then(|report| { + in_progress.commit()?; + Ok(report) + }) } }