Skip to content

A Rustic wrapper for the jsmn C library for parsing JSON.

Notifications You must be signed in to change notification settings

nsmryan/jsmn-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jmsn-rs

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.

Features

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.

TODO

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.

About

A Rustic wrapper for the jsmn C library for parsing JSON.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages