1use std::convert::TryFrom;
2use std::ffi::{CStr, CString, NulError};
3use std::ptr::null_mut;
4
5extern "C" {
6
7 fn error_type_to_string(error: libc::c_uint) -> *const libc::c_char;
8
9 fn create_input_stream(str: *const libc::c_char) -> *mut libc::c_void;
10
11}
12
13#[repr(C)]
15pub struct IInputStream {
16 pub(crate) handler : *mut libc::c_void
17}
18
19impl Default for IInputStream{
20 fn default() -> Self {
22 Self::null()
23 }
24}
25
26impl IInputStream {
27 pub fn null() -> Self {
29 IInputStream {
30 handler: null_mut()
31 }
32 }
33}
34
35impl TryFrom<String> for IInputStream {
36
37 type Error = NulError;
38 fn try_from(value: String) -> Result<Self, Self::Error> {
40 let cstring = CString::new(value)?;
41 let stream = IInputStream {
42 handler: unsafe {
43 create_input_stream(cstring.as_ptr())
44 }
45 };
46 Ok(stream)
47 }
48
49}
50
51#[repr(C)]
53pub struct TErrorInfo {
54 m_type: libc::c_uint,
55 m_line: libc::size_t
56}
57
58impl TErrorInfo {
59 pub fn get_line(&self) -> usize {
61 self.m_line
62 }
63
64 pub fn get_message(&self) -> Option<String> {
66 println!("{}", self.m_type);
67 Some(unsafe {
68 let msg = error_type_to_string(self.m_type);
69 CStr::from_ptr(msg).to_str().ok()?.to_owned()
70 })
71 }
72
73}