omp_gdk/types/
stringview.rs1#[derive(Copy, Clone, Debug)]
2#[repr(C)]
3pub struct StringView {
4 size: usize,
5 data: *const std::ffi::c_char,
6}
7
8impl Default for StringView {
9 fn default() -> Self {
10 Self::new(std::ptr::null(), 0)
11 }
12}
13
14impl StringView {
15 pub fn new(data: *const std::ffi::c_char, size: usize) -> Self {
16 StringView { data, size }
17 }
18
19 pub fn get_data(&self) -> String {
20 let cstr = unsafe { std::ffi::CStr::from_ptr(self.data) };
21 cstr.to_bytes().iter().map(|&c| c as char).collect()
22 }
23}
24
25impl From<&str> for StringView {
26 fn from(value: &str) -> Self {
27 StringView {
28 data: value.as_ptr().cast(),
29 size: value.len(),
30 }
31 }
32}