Unless Lance upstream conventions dictate otherwise, follow the defaults below. These are guidelines, not immutable constraints.
- Every
unsafeblock must have a// SAFETY:comment. Minimize unsafe scope. - All public FFI functions follow a two-layer pattern: an outer
#[no_mangle] pub unsafe extern "C"wrapper that converts between C types and error codes, and an inner function returningFfiResult<T>. See existing functions inrust/ffi/for the canonical pattern. - Return
0for success,-1for error. On error, store details viaset_last_error(code, message)into thread-local storage. C++ retrieves errors vialance_last_error_code()/lance_last_error_message(). - Transfer ownership to C with
Box::into_raw(); reclaim withBox::from_raw()in the correspondinglance_free_*()function. - When adding new error variants, append to the
ErrorCodeenum inrust/error.rsrather than reusing existing codes.