Crates.io | jsmn-rs |
lib.rs | jsmn-rs |
version | 0.2.0 |
source | src |
created_at | 2018-09-28 18:13:09.575336 |
updated_at | 2018-09-28 19:01:29.076533 |
description | Bindings and Rustic interface to the jsmn C library for JSON parsing |
homepage | https://github.com/nsmryan/jsmn-rs |
repository | |
max_upload_size | |
id | 87026 |
size | 213,328 |
The jsmn-rs crate provide a rustic interface to an absolute gem of a C library called jsmn. The jsmn library is a JSON parser which, in the words of its author, is fast, portable, and simple. It does no memory allocation, and does not build of a tree of nodes with pointers- instead it fills out an array of structures, and children are indicated by indices into the array.
The thing I love most about this library is its simplicity- it contains exactly 2 enums, 2 structs, and 2 functions, with a total of 1 header file and 1 .c file.
The rustic wrapping includes using bindgen to generate raw bindings, available from the raw module, and then wrapping those up in standard rust naming conventions. This means using slices instead of pointers and lengths, and returning a Result from jsmn_parse instead of a number that can be an error code or count.
This library provides two features, "parent-links" and "strict" which can be set when adding jsmn-rs as a dependancy in Cargo.toml. These add the pre-processor directives JSMN_PARENT_LINKS and JSMN_STRICT, respectively, when compiling jsmn and generating the jsmn bindings.
I've used this library without the strict setting as a quick way to read configuration files, and I've seen some benchmarks which show that the parent-links can increase performance enormously.
Ideally it would be tested on 64 and 32 bit machines, as I'm not sure whether the use of "int" in the C source will cause problems here. I tried to use isize and usize to make this okay, but for some casts it might still be a problem.
There are also very few tests and very little example code on how to use the library.