Skip to content

Commit 5935b8f

Browse files
add Env::from_raw constructor (rust-rocksdb#545)
Support usages where the caller already has an environment built by an alternative means, which the Env of this crate should take ownership of. Co-authored-by: Zaidoon Abd Al Hadi <zaidoon@cloudflare.com>
1 parent 7e9c78b commit 5935b8f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/env.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ impl Env {
5151
}
5252
}
5353

54+
/// Returns a new environment which wraps and takes ownership of the provided
55+
/// raw environment.
56+
///
57+
/// # Safety
58+
///
59+
/// Ownership of `env` is transferred to the returned Env, which becomes
60+
/// responsible for freeing it. The caller should forget the raw pointer
61+
/// after this call.
62+
///
63+
/// # When would I use this?
64+
///
65+
/// RocksDB's C++ [Env](https://github.com/facebook/rocksdb/blob/main/include/rocksdb/env.h)
66+
/// class provides many extension points for low-level database subsystems, such as file IO.
67+
/// These subsystems aren't covered within the scope of the C interface or this crate,
68+
/// but from_raw() may be used to hand a pre-instrumented Env to this crate for further use.
69+
///
70+
pub unsafe fn from_raw(env: *mut ffi::rocksdb_env_t) -> Self {
71+
Self(Arc::new(EnvWrapper { inner: env }))
72+
}
73+
5474
/// Sets the number of background worker threads of a specific thread pool for this environment.
5575
/// `LOW` is the default pool.
5676
///

0 commit comments

Comments
 (0)