sdf/
lib.rs

1//! Read .sdf files, full waveform data files from Riegl Laser Measurement Systems.
2//!
3//! This is in part a wrapper library around `libsdfifc.so`, Riegl's sdf library. This library also
4//! provides functions to convert .sdf files to discrete return .sdc files using Gaussian
5//! decomposition.
6//!
7//! The `sdfifc` library **is not thread-safe**, and so this library should only be used in
8//! single-threaded applications. When running this library's test suite, you must set
9//! `RUST_TEST_THREADS=1` or else you most likely will get a segfault.
10
11#![deny(box_pointers, fat_ptr_transmutes, missing_copy_implementations, missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces, unused_qualifications, unused_results, variant_size_differences)]
12
13extern crate libc;
14#[macro_use]
15extern crate log;
16extern crate peakbag;
17
18macro_rules! sdftry {
19    ($expr:expr) => {{
20        match $expr {
21            0 => {},
22            code @ _ => return Err(Error::from_i32(code)),
23        }
24    }}
25}
26
27pub mod convert;
28pub mod error;
29mod ffi;
30pub mod file;
31
32pub use error::Error;
33pub use file::File;
34
35use std::ffi::CStr;
36use std::ptr;
37use std::result;
38
39use libc::c_char;
40
41/// Container structure for information about the library.
42#[derive(Debug)]
43pub struct LibraryVersion {
44    /// The library's major api version.
45    pub api_major: u16,
46    /// The library's minor api version.
47    pub api_minor: u16,
48    /// The library's build version.
49    pub build_version: String,
50    /// The library's build tag.
51    pub build_tag: String,
52}
53
54/// Returns information about the fwifc library.
55///
56/// # Examples
57///
58/// ```
59/// let library_version = sdf::library_version();
60/// ```
61pub fn library_version() -> Result<LibraryVersion> {
62    unsafe {
63        let mut api_major = 0u16;
64        let mut api_minor = 0u16;
65        let mut build_version: *const c_char = ptr::null_mut();
66        let mut build_tag: *const c_char = ptr::null_mut();
67        sdftry!(ffi::fwifc_get_library_version(&mut api_major,
68                                               &mut api_minor,
69                                               &mut build_version,
70                                               &mut build_tag));
71        Ok(LibraryVersion {
72            api_major: api_major,
73            api_minor: api_minor,
74            build_version: try!(CStr::from_ptr(build_version).to_str()).to_string(),
75            build_tag: try!(CStr::from_ptr(build_tag).to_str()).to_string(),
76        })
77    }
78}
79
80/// Our custom result type.
81pub type Result<T> = result::Result<T, Error>;