use crate::Error;
cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
pub(crate) mod linux;
use self::linux as platform;
} else if #[cfg(windows)] {
pub mod windows;
use self::windows as platform;
} else {
compile_error!("unsupported platform");
}
}
#[derive(Debug)]
pub struct BrightnessDevice(platform::BlockingDeviceImpl);
pub trait Brightness {
fn device_name(&self) -> Result<String, Error>;
fn friendly_device_name(&self) -> Result<String, Error>;
fn get(&self) -> Result<u32, Error>;
fn set(&self, percentage: u32) -> Result<(), Error>;
}
impl Brightness for BrightnessDevice {
fn device_name(&self) -> Result<String, Error> {
self.0.device_name()
}
fn friendly_device_name(&self) -> Result<String, Error> {
self.0.friendly_device_name()
}
fn get(&self) -> Result<u32, Error> {
self.0.get()
}
fn set(&self, percentage: u32) -> Result<(), Error> {
self.0.set(percentage)
}
}
pub fn brightness_devices() -> impl Iterator<Item = Result<BrightnessDevice, Error>> {
platform::brightness_devices().map(|r| r.map(BrightnessDevice).map_err(Into::into))
}