Skip to main content

miracle_plugin/
application.rs

1use super::bindings;
2use std::ffi::CStr;
3
4#[derive(Debug, Clone)]
5pub struct ApplicationInfo {
6    /// The name of the application.
7    pub name: String,
8
9    /// The internal id of the application
10    pub internal: u64,
11}
12
13impl ApplicationInfo {
14    /// Create from the C struct.
15    ///
16    /// # Safety
17    /// The `application_name` pointer must be valid and null-terminated.
18    pub unsafe fn from_c(value: &bindings::miracle_application_info_t) -> Self {
19        let name = if value.application_name.is_null() {
20            String::new()
21        } else {
22            unsafe {
23                CStr::from_ptr(value.application_name)
24                    .to_string_lossy()
25                    .into_owned()
26            }
27        };
28        Self {
29            name,
30            internal: value.internal,
31        }
32    }
33}