meilisearch / heed

A fully typed LMDB wrapper with minimum overhead 🐦
https://docs.rs/heed
MIT License
569 stars 52 forks source link

Replace the restrictive `&mut RwTxn` by less restrictive `&RwTxn` #190

Closed Kerollmops closed 4 months ago

Kerollmops commented 1 year ago

The PR fixes #189 by removing all of the &mut RwTxn requirements by simple &RwTxn. If you want to understand the new possibilities I advise you to look at the example showcase non-mutable-rwtxn.

Doing so allows very cool use cases like:

let wtxn = env.write_txn()?;
for result in database1.iter(&wtxn)? {
    let (k, v) = result?;
    database2.put(&wtxn, k, v)?; // It now compiles and works perfectly 🎉
}
Kerollmops commented 4 months ago

Closed because it is unsafe to implement it like that. We must consider a more restrictive way to let users copy the content from one database into another.