diff --git a/lib/revisionstore/src/lib.rs b/lib/revisionstore/src/lib.rs index f83fbdf21a..b8f2b3357a 100644 --- a/lib/revisionstore/src/lib.rs +++ b/lib/revisionstore/src/lib.rs @@ -5,6 +5,8 @@ #[macro_use] extern crate failure; +mod unionstore; + pub mod error; pub mod datastore; pub mod key; diff --git a/lib/revisionstore/src/unionstore.rs b/lib/revisionstore/src/unionstore.rs new file mode 100644 index 0000000000..4419ded7d7 --- /dev/null +++ b/lib/revisionstore/src/unionstore.rs @@ -0,0 +1,46 @@ +// Copyright Facebook, Inc. 2018 +// Union store + +use std::cell::RefCell; +use std::vec::IntoIter; + +pub struct UnionStore { + stores: RefCell>, +} + +pub struct UnionStoreIterator(IntoIter); + +impl UnionStore { + pub fn new() -> UnionStore { + UnionStore { + stores: RefCell::new(vec![]), + } + } + + pub fn add(&mut self, item: T) + where + T: Clone, + { + self.stores.borrow_mut().push(item) + } +} + +impl<'a, T> IntoIterator for &'a UnionStore +where + T: Clone, +{ + type Item = T; + type IntoIter = UnionStoreIterator; + + fn into_iter(self) -> Self::IntoIter { + UnionStoreIterator(self.stores.borrow().clone().into_iter()) + } +} + +impl Iterator for UnionStoreIterator { + type Item = T; + + fn next(&mut self) -> Option { + self.0.next() + } +}