INNER CODE UNIT · Rust
to_handle
deepjavalibrary/djl · extensions/tokenizers/rust/src/lib.rs:926
fn to_handle<T: 'static>(val: T) -> jlong {
let handle = Box::into_raw(Box::new(val)) as jlong;
handle
}
fn cast_handle<T>(handle: jlong) -> &'static mut T {
assert_ne!(handle, 0, "Invalid handle value");
let ptr = handle as *mut T;
unsafe { &mut *ptr }
}
fn drop_handle<T: 'static>(handle: jlong) {
unsafe {
let _ = Box::from_raw(handle as *mut T);
}
}