aboutsummaryrefslogtreecommitdiff
path: root/src/db/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/lib.rs')
-rw-r--r--src/db/lib.rs30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/db/lib.rs b/src/db/lib.rs
index 4543e53c..ed1bdb75 100644
--- a/src/db/lib.rs
+++ b/src/db/lib.rs
@@ -166,15 +166,18 @@ impl Tree {
.transpose()
}
- /// True if item didn't exist before, false if item already existed
- /// and was replaced.
+ /// Returns the old value if there was one
#[inline]
- pub fn insert<T: AsRef<[u8]>, U: AsRef<[u8]>>(&self, key: T, value: U) -> Result<bool> {
+ pub fn insert<T: AsRef<[u8]>, U: AsRef<[u8]>>(
+ &self,
+ key: T,
+ value: U,
+ ) -> Result<Option<Value>> {
self.0.insert(self.1, key.as_ref(), value.as_ref())
}
- /// True if item was removed, false if item already didn't exist
+ /// Returns the old value if there was one
#[inline]
- pub fn remove<T: AsRef<[u8]>>(&self, key: T) -> Result<bool> {
+ pub fn remove<T: AsRef<[u8]>>(&self, key: T) -> Result<Option<Value>> {
self.0.remove(self.1, key.as_ref())
}
@@ -220,20 +223,19 @@ impl<'a> Transaction<'a> {
self.0.len(tree.1)
}
- /// True if item didn't exist before, false if item already existed
- /// and was replaced.
+ /// Returns the old value if there was one
#[inline]
pub fn insert<T: AsRef<[u8]>, U: AsRef<[u8]>>(
&mut self,
tree: &Tree,
key: T,
value: U,
- ) -> Result<bool> {
+ ) -> Result<Option<Value>> {
self.0.insert(tree.1, key.as_ref(), value.as_ref())
}
- /// True if item was removed, false if item already didn't exist
+ /// Returns the old value if there was one
#[inline]
- pub fn remove<T: AsRef<[u8]>>(&mut self, tree: &Tree, key: T) -> Result<bool> {
+ pub fn remove<T: AsRef<[u8]>>(&mut self, tree: &Tree, key: T) -> Result<Option<Value>> {
self.0.remove(tree.1, key.as_ref())
}
@@ -289,8 +291,8 @@ pub(crate) trait IDb: Send + Sync {
fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value>>;
fn len(&self, tree: usize) -> Result<usize>;
- fn insert(&self, tree: usize, key: &[u8], value: &[u8]) -> Result<bool>;
- fn remove(&self, tree: usize, key: &[u8]) -> Result<bool>;
+ fn insert(&self, tree: usize, key: &[u8], value: &[u8]) -> Result<Option<Value>>;
+ fn remove(&self, tree: usize, key: &[u8]) -> Result<Option<Value>>;
fn iter(&self, tree: usize) -> Result<ValueIter<'_>>;
fn iter_rev(&self, tree: usize) -> Result<ValueIter<'_>>;
@@ -315,8 +317,8 @@ pub(crate) trait ITx {
fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value>>;
fn len(&self, tree: usize) -> Result<usize>;
- fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> Result<bool>;
- fn remove(&mut self, tree: usize, key: &[u8]) -> Result<bool>;
+ fn insert(&mut self, tree: usize, key: &[u8], value: &[u8]) -> Result<Option<Value>>;
+ fn remove(&mut self, tree: usize, key: &[u8]) -> Result<Option<Value>>;
fn iter(&self, tree: usize) -> Result<ValueIter<'_>>;
fn iter_rev(&self, tree: usize) -> Result<ValueIter<'_>>;