hdf5_bitshuffle/
lib.rs

1//! This is a Rust binding of bitshuffle HDF5 filter.
2//! Some HDF5 files use this not standard plugin
3//! [bitshuffle](https://github.com/kiyo-masui/bitshuffle)
4//! (mainly produced by the Dectris Eiger detectors).
5//! This crate makes a binding for Rust.
6//!
7//! To use this plugin just call in your code before using any HDF5 API:
8//! ```rust
9//! use hdf5_bitshuffle::register_bitshuffle_plugin;
10//!
11//! fn main() {
12//!      register_bitshuffle_plugin();
13//! }
14//! ```
15//! Or, if you want more control, you can call it manually:
16//! ```rust
17//! use std::sync::Once;
18//! use hdf5_bitshuffle::bshuf_register_h5filter;
19//!
20//! static REGISTER_BITSHUFFLE: Once = Once::new();
21//!
22//! fn main() {
23//!     unsafe {
24//!         REGISTER_BITSHUFFLE.call_once(|| {
25//!                 if bshuf_register_h5filter() < 0 {
26//!                     panic!("Could not register bitshuffle plugin for HDF5");
27//!                 }
28//!             });
29//!         }
30//! }
31//! ```
32#![allow(non_upper_case_globals)]
33#![allow(non_camel_case_types)]
34#![allow(non_snake_case)]
35
36use std::sync::Once;
37
38extern "C" {
39    /// Unsafe function to registers the bitshuffle plugin.
40    pub fn bshuf_register_h5filter() -> ::std::os::raw::c_int;
41}
42
43static REGISTER_BITSHUFFLE: Once = Once::new();
44
45/// Convenient safe rust function to register the bitshuffle plugin.
46/// It just panics if it fails.
47pub fn register_bitshuffle_plugin() {
48    REGISTER_BITSHUFFLE.call_once(|| {
49        if unsafe { bshuf_register_h5filter() < 0 } {
50            panic!("Could not register bitshuffle plugin for HDF5");
51        }
52    });
53}