42 lines
1.0 KiB
Rust
42 lines
1.0 KiB
Rust
|
use std::ffi::{c_char, c_void, CString};
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
pub struct PluginInfo {
|
||
|
ptrs: PluginInfoPtrs,
|
||
|
_name: CString,
|
||
|
_version: CString,
|
||
|
_license: CString
|
||
|
}
|
||
|
|
||
|
#[repr(C)]
|
||
|
#[derive(Debug)]
|
||
|
struct PluginInfoPtrs {
|
||
|
name: *const c_char,
|
||
|
version: *const c_char,
|
||
|
license: *const c_char,
|
||
|
}
|
||
|
|
||
|
impl PluginInfo {
|
||
|
pub fn new(name: &str, version: &str, license: &str) -> Self {
|
||
|
|
||
|
let _name = CString::new(name).unwrap();
|
||
|
let _version = CString::new(version).unwrap();
|
||
|
let _license = CString::new(license).unwrap();
|
||
|
let name = _name.as_ptr();
|
||
|
let version = if _version.is_empty() {
|
||
|
std::ptr::null()
|
||
|
} else {_version.as_ptr()};
|
||
|
let license = if _license.is_empty() {
|
||
|
std::ptr::null()
|
||
|
} else {_license.as_ptr()};
|
||
|
|
||
|
Self { ptrs: PluginInfoPtrs{ name, version, license }, _name, _version, _license }
|
||
|
}
|
||
|
|
||
|
pub fn get_raw_ptr(&self) -> *const c_void {
|
||
|
&self.ptrs as *const _ as *const c_void
|
||
|
}
|
||
|
}
|
||
|
unsafe impl Sync for PluginInfo {}
|
||
|
|