docs

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.

  • pub fn new(value: T) -> Handle<T>§

    Source

    A handle holding value, kept alive until release.

  • pub unsafe fn from_ptr(p: CPtr<c_void>) -> Handle<T>§

    Source

    The handle C gave back as its void*. It must come from Handle::<T>::new(..).as_ptr() with this T; get panics on another type or a released handle.

  • pub fn as_ptr(self) -> CPtr<c_void>§

    Source

    The void* to pass to C.

  • pub fn get(self) -> T§

    Source

    The value: the same object for a List, Dict or other shared value, a copy of a plain one. Panics after the last release.

  • pub fn set(self, value: T)§

    Source

    Replace the value every copy of the handle sees.

  • pub fn retain(self)§

    Source

    One more release before the value is let go: for C code that keeps a second copy of the pointer.

  • pub fn release(self)§

    Source

    Let the value go once C is done with the pointer (after as many releases as new and retains). A get afterwards panics.

Trait implementations 3
  • impl<T> Clone for Handle<T>
  • impl<T> Copy for Handle<T>
  • impl<T> Debug for Handle<T>