1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// industrial-io/src/lib.rs
//
// Copyright (c) 2018, Frank Pagliughi
//
// Licensed under the MIT license:
//   <LICENSE or http://opensource.org/licenses/MIT>
// This file may not be copied, modified, or distributed except according
// to those terms.
//
//!
//!

//#[macro_use]
extern crate nix;

#[macro_use]
extern crate error_chain;

extern crate libiio_sys as ffi;

use std::ffi::CStr;
use std::os::raw::c_char;

pub use context::*;
pub use device::*;
pub use channel::*;
pub use buffer::*;
pub use errors::*;

pub mod context;
pub mod device;
pub mod channel;
pub mod buffer;
pub mod errors;

fn cstring_opt(pstr: *const c_char) -> Option<String> {
    if pstr.is_null() {
        None
    }
    else {
        let name = unsafe { CStr::from_ptr(pstr) };
        Some(name.to_str().unwrap_or_default().to_string())
    }
}


// --------------------------------------------------------------------------

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}