Rust crate mirroring the C API header file (k.h
) for kdb+. The expected usage is to build a
shared library for kdb+ in Rust.
In order to avoid writing too large unsafe
block leading to poor optimization, most of native C API functions were provided
with a wrapper funtion with a bit of ergonomic safety and with intuitive implementation as a trait method. The only exceptions
are knk
and k
which are using elipsis (...
) as its argument. These functions are provided under native
namespace with the other C API functions.
Note
- This library is for kdb+ version >= 3.0.
- Meangless C macros are excluded but accessors of an underlying array like
kC
,kJ
,kK
etc. are provided in Rust way. - IPC interface is in development. Once the feature is added. This crate will be merged under different crate, say
rustkdb
.
Examples
The examples of using C API wrapper are included in c_api_examples
folder. The examples are mirroring the examples in the document of kdb_c_api
library and the functions are also used for simple tests of the library. The test is conducted in the test.q
under tests/
by loading the functions defined in a shared library built from the examples.
Here are some examples:
C API Style
use *;
use *;
pub extern "C"
pub extern "C"
pub extern "C"
q can use these functions like this:
q)summon:`libc_api_examples 2: (`create_symbol_list; 1)
q)summon[]
`Abraham`Isaac`Jacob`Joseph
q)`Abraham`Isaac`Jacob`Joseph ~ summon[]
q)catchy: `libc_api_examples 2: (`catchy; 2);
q)catchy[$; ("J"; "42")]
42
q)catchy[+; (1; `a)]
error: type
q)unfortunate_fact: `libc_api_examples 2: (`dictionary_list_to_table; 1);
q)unfortunate_fact[]
a b
------
0 0
10 100
20 200
Rust Style
The examples below are written without unsafe
code. You can see how comfortably breathing are the wrapped functions in the code.
use *;
pub extern "C"
pub extern "C"
And q code is here:
q)summon:`libc_api_examples 2: (`create_symbol_list2; 1)
q)summon[]
`Abraham`Isaac`Jacob`Joseph
q)chill: `libc_api_examples 2: (`no_panick; 2);
q)chill[$; ("J"; "42")]
success!
42
q)chill[+; (1; `a)]
FYI: type
q)climate_change: libc_api_examples 2: (`create_table2; 1);
q)climate_change[]
time temperature
-----------------------------------------
2003.10.10D02:24:19.167018272 22.1
2006.05.24D06:16:49.419710368 24.7
2008.08.12D23:12:24.018691392 30.5