make the keyspace methods non-public

This commit is contained in:
Riley Apeldoorn 2024-04-20 23:46:53 +02:00
parent 21294f58ee
commit f8ebdce372

View file

@ -334,7 +334,7 @@ struct Keyspace<'db> {
impl<'db> Keyspace<'db> { impl<'db> Keyspace<'db> {
/// Retrieve a value from the database. Returns `Missing` if the key does not exist. /// Retrieve a value from the database. Returns `Missing` if the key does not exist.
pub fn get(&self, key: impl AsRef<[u8]>) -> Result<impl AsRef<[u8]> + 'db> { fn get(&self, key: impl AsRef<[u8]>) -> Result<impl AsRef<[u8]> + 'db> {
self.tx self.tx
.inner .inner
.get_pinned_cf(&self.cf, key) .get_pinned_cf(&self.cf, key)
@ -342,25 +342,25 @@ impl<'db> Keyspace<'db> {
.and_then(|opt| opt.ok_or(Error::Missing)) .and_then(|opt| opt.ok_or(Error::Missing))
} }
/// Set the value at `key` to `val`. /// Set the value at `key` to `val`.
pub fn set(&self, key: impl AsRef<[u8]>, val: impl AsRef<[u8]>) -> Result<()> { fn set(&self, key: impl AsRef<[u8]>, val: impl AsRef<[u8]>) -> Result<()> {
self.tx self.tx
.inner .inner
.put_cf(&self.cf, key, val) .put_cf(&self.cf, key, val)
.map_err(Error::Internal) .map_err(Error::Internal)
} }
/// Delete the key-value pair identified by `key`. /// Delete the key-value pair identified by `key`.
pub fn del(&self, key: impl AsRef<[u8]>) -> Result<()> { fn del(&self, key: impl AsRef<[u8]>) -> Result<()> {
self.tx.inner.delete_cf(&self.cf, &key)?; self.tx.inner.delete_cf(&self.cf, &key)?;
OK OK
} }
/// Remove the key and associated value from the keyspace, and return its previous value. /// Remove the key and associated value from the keyspace, and return its previous value.
pub fn pop(&self, key: impl AsRef<[u8]>) -> Result<Option<Vec<u8>>> { fn pop(&self, key: impl AsRef<[u8]>) -> Result<Option<Vec<u8>>> {
let old = self.tx.inner.get_for_update_cf(&self.cf, &key, true)?; let old = self.tx.inner.get_for_update_cf(&self.cf, &key, true)?;
self.del(key)?; self.del(key)?;
Ok(old) Ok(old)
} }
/// Check whether the key exists in the keyspace. /// Check whether the key exists in the keyspace.
pub fn has(&self, key: impl AsRef<[u8]>) -> Result<bool> { fn has(&self, key: impl AsRef<[u8]>) -> Result<bool> {
self.tx self.tx
.inner .inner
.get_pinned_cf(&self.cf, key) .get_pinned_cf(&self.cf, key)
@ -368,7 +368,7 @@ impl<'db> Keyspace<'db> {
.map(|opt| opt.is_some()) .map(|opt| opt.is_some())
} }
/// Execute a prefix scan. /// Execute a prefix scan.
pub fn scan( fn scan(
&self, &self,
prefix: impl AsRef<[u8]> + 'db, prefix: impl AsRef<[u8]> + 'db,
) -> impl Iterator<Item = Result<(impl AsRef<[u8]> + 'static, impl AsRef<[u8]> + 'static)>> + 'db ) -> impl Iterator<Item = Result<(impl AsRef<[u8]> + 'static, impl AsRef<[u8]> + 'static)>> + 'db
@ -386,7 +386,7 @@ impl<'db> Keyspace<'db> {
.map(|r| r.map_err(Error::Internal)) .map(|r| r.map_err(Error::Internal))
} }
/// Show all items in the entire keyspace. /// Show all items in the entire keyspace.
pub fn list( fn list(
&self, &self,
) -> impl Iterator<Item = Result<(impl AsRef<[u8]> + 'static, impl AsRef<[u8]> + 'static)>> + 'db ) -> impl Iterator<Item = Result<(impl AsRef<[u8]> + 'static, impl AsRef<[u8]> + 'static)>> + 'db
{ {