rust-rocksdb-zaidoon1/tests/fail/memory_usage_builder_outlive_db.rs
Evan Jones 4b9ba976d6 MemoryUsageBuilder: Prevent outliving the DBs/caches (#1061)
This type must not outlive the DBs and caches that are added to it,
otherwise the caller will access invalid memory and likely crash.
Use PhantomData to ensure it does not outlive its arguments. This is
technically a breaking API change, but anything that used this code
in this way was likely broken anyway.

Co-authored-by: Oleksandr Anyshchenko <aanischenko@gmail.com>
2026-01-06 22:13:21 -05:00

10 lines
265 B
Rust

use rust_rocksdb::{perf::MemoryUsageBuilder, DB};
fn main() {
let mut builder = MemoryUsageBuilder::new().unwrap();
{
let db = DB::open_default("foo").unwrap();
builder.add_db(&db);
}
let _memory_usage = builder.build().unwrap();
}