mastrust_ls_lib/cdef/mastrust/raw/
include.rs1include!(concat!(env!("OUT_DIR"), "/mastrust_bindings.rs"));
8use std::ffi::CString;
9use std::ptr;
10
11pub struct TokenRaw {
12 pub typ: *mut ::std::os::raw::c_char,
13 pub value: *mut u8,
14 pub string: *mut ::std::os::raw::c_char,
15 pub length: u8,
16 token: CToken,
17}
18
19impl TokenRaw {
20
21 pub fn new(_string: CString) -> Self {
22 let cstring = _string.to_str().unwrap();
23 let c_char_string = std::ffi::CString::new(cstring).expect("Failed to create CString.");
25 let c_char_ptr: *mut ::std::os::raw::c_char = c_char_string.into_raw();
26
27 let _token = CToken {
28 type_: c_char_ptr,
29 value: ptr::null_mut(),
30 string: c_char_ptr,
31 length: ptr::null_mut(), };
33
34 let mut token_raw = TokenRaw {
35 typ: c_char_ptr,
36 value: ptr::null_mut(),
37 string: c_char_ptr,
38 length: 0,
39 token: _token,
40 };
41
42 unsafe {
43 ctoken_init(&mut token_raw.token, c_char_ptr);
44 }
45
46 token_raw
47 }
48
49 pub fn tokenize(&mut self) {
50 let _token = &mut self.token;
51 unsafe {
52 ctoken_tokenize(_token);
53 self.value = (*_token).value;
54 self.length = (*_token).length as u8; }
56 }
57
58 pub fn get_token(&self) -> Vec<u8> {
59 unsafe {
60 if self.value.is_null() {
61 return Vec::new();
62 }
63 Vec::from_raw_parts(self.value, self.length as usize, self.length as usize)
64 }
65 }
66}