Skip to content

Commit

Permalink
Merge pull request #251 from nolanderc/fn-once-reserve
Browse files Browse the repository at this point in the history
replace all `FnMut` with `FnOnce` in `put_reserve_*`
  • Loading branch information
Kerollmops committed Apr 29, 2024
2 parents 1d35f42 + 8aa5de3 commit 7e2e105
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions heed/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ impl<'txn> RwCursor<'txn> {
flags: PutFlags,
key: &[u8],
data_size: usize,
mut write_func: F,
write_func: F,
) -> Result<bool>
where
F: FnMut(&mut ReservedSpace) -> io::Result<()>,
F: FnOnce(&mut ReservedSpace) -> io::Result<()>,
{
let mut key_val = crate::into_val(key);
let mut reserved = ffi::reserve_size_val(data_size);
Expand All @@ -353,7 +353,7 @@ impl<'txn> RwCursor<'txn> {
};

let mut reserved = ReservedSpace::from_val(reserved);
(write_func)(&mut reserved)?;
write_func(&mut reserved)?;

if reserved.remaining() == 0 {
Ok(found)
Expand Down
6 changes: 3 additions & 3 deletions heed/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1882,11 +1882,11 @@ impl<KC, DC, C> Database<KC, DC, C> {
txn: &mut RwTxn,
key: &'a KC::EItem,
data_size: usize,
mut write_func: F,
write_func: F,
) -> Result<()>
where
KC: BytesEncode<'a>,
F: FnMut(&mut ReservedSpace) -> io::Result<()>,
F: FnOnce(&mut ReservedSpace) -> io::Result<()>,
{
assert_eq_env_db_txn!(self, txn);

Expand All @@ -1900,7 +1900,7 @@ impl<KC, DC, C> Database<KC, DC, C> {
}

let mut reserved = unsafe { ReservedSpace::from_val(reserved) };
(write_func)(&mut reserved)?;
write_func(&mut reserved)?;
if reserved.remaining() == 0 {
Ok(())
} else {
Expand Down
4 changes: 2 additions & 2 deletions heed/src/iterator/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl<'txn, KC, DC, IM> RwIter<'txn, KC, DC, IM> {
) -> Result<bool>
where
KC: BytesEncode<'a>,
F: FnMut(&mut ReservedSpace) -> io::Result<()>,
F: FnOnce(&mut ReservedSpace) -> io::Result<()>,
{
let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?;
self.cursor.put_current_reserved_with_flags(flags, &key_bytes, data_size, write_func)
Expand Down Expand Up @@ -648,7 +648,7 @@ impl<'txn, KC, DC, IM> RwRevIter<'txn, KC, DC, IM> {
) -> Result<bool>
where
KC: BytesEncode<'a>,
F: FnMut(&mut ReservedSpace) -> io::Result<()>,
F: FnOnce(&mut ReservedSpace) -> io::Result<()>,
{
let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?;
self.cursor.put_current_reserved_with_flags(flags, &key_bytes, data_size, write_func)
Expand Down
4 changes: 2 additions & 2 deletions heed/src/iterator/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl<'txn, KC, DC, C, IM> RwPrefix<'txn, KC, DC, C, IM> {
) -> Result<bool>
where
KC: BytesEncode<'a>,
F: FnMut(&mut ReservedSpace) -> io::Result<()>,
F: FnOnce(&mut ReservedSpace) -> io::Result<()>,
{
let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?;
self.cursor.put_current_reserved_with_flags(flags, &key_bytes, data_size, write_func)
Expand Down Expand Up @@ -682,7 +682,7 @@ impl<'txn, KC, DC, C, IM> RwRevPrefix<'txn, KC, DC, C, IM> {
) -> Result<bool>
where
KC: BytesEncode<'a>,
F: FnMut(&mut ReservedSpace) -> io::Result<()>,
F: FnOnce(&mut ReservedSpace) -> io::Result<()>,
{
let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?;
self.cursor.put_current_reserved_with_flags(flags, &key_bytes, data_size, write_func)
Expand Down
4 changes: 2 additions & 2 deletions heed/src/iterator/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl<'txn, KC, DC, IM> RwRange<'txn, KC, DC, IM> {
) -> Result<bool>
where
KC: BytesEncode<'a>,
F: FnMut(&mut ReservedSpace) -> io::Result<()>,
F: FnOnce(&mut ReservedSpace) -> io::Result<()>,
{
let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?;
self.cursor.put_current_reserved_with_flags(flags, &key_bytes, data_size, write_func)
Expand Down Expand Up @@ -738,7 +738,7 @@ impl<'txn, KC, DC, IM> RwRevRange<'txn, KC, DC, IM> {
) -> Result<bool>
where
KC: BytesEncode<'a>,
F: FnMut(&mut ReservedSpace) -> io::Result<()>,
F: FnOnce(&mut ReservedSpace) -> io::Result<()>,
{
let key_bytes: Cow<[u8]> = KC::bytes_encode(key).map_err(Error::Encoding)?;
self.cursor.put_current_reserved_with_flags(flags, &key_bytes, data_size, write_func)
Expand Down

0 comments on commit 7e2e105

Please sign in to comment.