bare::ffi::handle
API 参考只有英文版,由标准库源代码中的英文文档注释生成。
Nabi values C code holds as a void*.
A C API that calls back takes a void* user_data and hands it to the
callback. Handle::new(v) keeps v alive (a GC root) until
release, and h.as_ptr() is the void* to pass. The callback turns
it back with Handle::<T>::from_ptr(p) and reads the value with
get. A List, Dict or other shared value comes back as the same
object; a plain value is copied in.
The pointer is a handle number, never null and never a real address.
A closure is a value too: keep one in a handle and call it from a
one-line extern "C" fn.
Structs
HandleSource
pub struct Handle<T>A Nabi value of type T that C holds as a void*. Pointer-sized
and Copy: it may be a field of a #[repr(C)] struct.
A handle holding
value, kept alive untilrelease.The handle C gave back as its
void*. It must come fromHandle::<T>::new(..).as_ptr()with thisT;getpanics on another type or a released handle.The
void*to pass to C.The value: the same object for a
List,Dictor other shared value, a copy of a plain one. Panics after the lastrelease.Replace the value every copy of the handle sees.
One more
releasebefore the value is let go: for C code that keeps a second copy of the pointer.Let the value go once C is done with the pointer (after as many
releases asnewandretains). Agetafterwards panics.