sz_rust_sdk/core/
product.rs

1//! Core implementation of SzProduct trait
2
3use crate::{error::SzResult, traits::SzProduct, types::JsonString};
4
5/// Core implementation of the SzProduct trait
6pub struct SzProductCore;
7
8impl SzProductCore {
9    /// Creates a new SzProductCore without initializing the native library.
10    /// Caller must ensure SzProduct_init has already been called.
11    pub(crate) fn new() -> SzResult<Self> {
12        Ok(Self)
13    }
14}
15
16impl SzProduct for SzProductCore {
17    fn get_license(&self) -> SzResult<JsonString> {
18        let license_ptr = unsafe { crate::ffi::SzProduct_getLicense() };
19        if license_ptr.is_null() {
20            return Err(crate::error::SzError::unknown("Failed to get license"));
21        }
22        unsafe { crate::ffi::helpers::c_str_to_string_no_free(license_ptr) }
23    }
24
25    fn get_version(&self) -> SzResult<JsonString> {
26        let version_ptr = unsafe { crate::ffi::SzProduct_getVersion() };
27        if version_ptr.is_null() {
28            return Err(crate::error::SzError::unknown("Failed to get version"));
29        }
30        unsafe { crate::ffi::helpers::c_str_to_string_no_free(version_ptr) }
31    }
32}
33
34// Note: SzProductCore no longer needs Drop implementation
35// since it doesn't manage any resources directly