niso-base
Generated from crates/niso-base/CONTRACT.md when the site was built at 7aa23e2.
Purpose
Section titled “Purpose”The vocabulary every niso crate shares: object handles (Obj), the error
type every API returns (ErrorCode, Error, Result), and the C value
types the generated shims read arguments through and write results into. It
owns no state, runs nothing and has no dependencies, so any crate can depend
on it, and a change to it rebuilds everything: it changes rarely and
deliberately.
It does not own interface ids (InterfaceId stays the generated enum in
niso-core until niso-compose hashes names, migration step 6), the conversion
from storage’s DriverError (niso-core until step 5), or the IDL callback
structs (function pointer, userdata, destructor), which niso-idl generates per
callback signature into the crate that owns the IDL.
Public surface
Section titled “Public surface”- Rust:
Obj(au64handle,#[repr(transparent)]) andOBJECT_BIT.ErrorCode(#[repr(i32)]),Error { code, message },Result<T>,err(code, message).c:NisoStr,NisoBytes,NisoHandles,NisoStrs,NisoHeldandHeld,DropFn,BufferOrString,BytesOrStr,SharedBytesOrStr,NodeOrString,PairsOrString, and the readersstr_in,opt_str_in,strs_in,bytes_in,bytes_mut_in,opt_bytes_in,slice_in,buffer_or_string_in,obj_in,opt_obj_in,dict_in.testing(below) and, behind thecontract-testsfeature,contract.
- C (include/status.h and include/types.h, sections of the composed
niso_runtime.h):
enum niso_statusholdsErrorCode‘s values;niso_str,niso_bytes,niso_handles,niso_strs,niso_node_or_string,niso_buffer_or_string,niso_heldandniso_drop_fnare thectypes’ layouts. - IDL: none.
- Glue: none. The glue core’s code-to-name table (
makeError, bindings/js/glue/exceptions.js) mirrorsErrorCode.
niso-core re-exports all of it under the old paths (niso_core::Obj,
niso_core::ErrorCode, niso_core::ffi::NisoStr, …).
Host requirements
Section titled “Host requirements”None.
May assume from dependencies
Section titled “May assume from dependencies”No niso dependencies and no third-party ones.
Guarantees
Section titled “Guarantees”ErrorCode’s numeric values are ABI: each equals itsNISO_*constant in include/status.h, every constant butNISO_OK = 0is anErrorCode, and the values are distinct and non-zero. contract::error_codes, run on include/status.h, the section of the header the C API ships that is the one source of the numbers.- A handle is one
u64. Object handles setOBJECT_BIT(the top bit); handles without it are nodes, whose meaning only the document knows. 0 is no object:obj_in(0)is a TypeError andopt_obj_in(0)isNone. contract::handles. - The C value structs are a pointer and a length (plus
is_stringforBufferOrString, a handle forNodeOrString), in C layout. contract::layouts. - Readers never dereference null: a null pointer reads as empty (bytes,
slices),
""for a zero-length string,Nonefor theopt_forms, and a TypeError where a value is required; text that is not UTF-8 is a TypeError. contract::conversions. - A
NisoHeldwith nulldatais no value; a takenHeldcalls the binding’sdropexactly once, when it is dropped. contract::held.
Threads
Section titled “Threads”Everything here is plain data. The c structs hold raw pointers and are not
Send; their validity is the caller’s, as the unsafe readers document.
Performance and memory
Section titled “Performance and memory”No allocation except strs_in (a Vec of borrowed &str) and Error’s
message. Its code in niso-app is a few hundred bytes.
testing::DropProbe makes NisoHeld values whose destructor bumps a
counter, for tests that a value is dropped exactly once. testing::c_str
borrows a Rust string as a C value. Nothing else here needs faking.
Standalone use
Section titled “Standalone use”Shared types only. cargo test -p niso-base runs the contract suite.