Skip to main content

lingxia_platform/traits/
device.rs

1use crate::error::PlatformError;
2use crate::{DeviceInfo, ScreenInfo};
3
4pub trait Device: Send + Sync + 'static {
5    fn device_info(&self) -> DeviceInfo;
6    fn screen_info(&self) -> ScreenInfo;
7    fn vibrate(&self, long: bool) -> Result<(), PlatformError>;
8    fn make_phone_call(&self, phone_number: &str) -> Result<(), PlatformError>;
9}
10
11pub trait DeviceHardware: Send + Sync + 'static {
12    /// Get total physical memory in bytes.
13    fn get_memory_info(&self) -> Result<u64, PlatformError> {
14        Err(PlatformError::NotSupported(
15            "get_memory_info not implemented".to_string(),
16        ))
17    }
18
19    /// Get the number of logical CPU cores available.
20    fn get_cpu_count(&self) -> usize {
21        std::thread::available_parallelism()
22            .map(|count| count.get())
23            .unwrap_or(1)
24    }
25
26    /// Get total ROM storage in bytes.
27    fn get_storage_total_bytes(&self) -> Result<u64, PlatformError> {
28        Err(PlatformError::NotSupported(
29            "get_storage_total_bytes not implemented".to_string(),
30        ))
31    }
32}