Rewrote impl_cast as a proc_macro to make it easier to work with
This commit is contained in:
@@ -4,11 +4,12 @@ use crate::{
|
||||
errors::{DeviceError, ErrorCode},
|
||||
request::execute::CommandType,
|
||||
response,
|
||||
traits::{As, OnOff, Scene, Trait},
|
||||
traits::{OnOff, Scene, Trait},
|
||||
types::Type,
|
||||
};
|
||||
|
||||
pub trait GoogleHomeDevice: As<dyn OnOff> + As<dyn Scene> + 'static {
|
||||
#[impl_cast::device(As: OnOff + Scene)]
|
||||
pub trait GoogleHomeDevice: Sync + Send + 'static {
|
||||
fn get_device_type(&self) -> Type;
|
||||
fn get_device_name(&self) -> Name;
|
||||
fn get_id(&self) -> &str;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{device::GoogleHomeDevice, errors::ErrorCode};
|
||||
use crate::errors::ErrorCode;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub enum Trait {
|
||||
@@ -10,11 +10,8 @@ pub enum Trait {
|
||||
Scene,
|
||||
}
|
||||
|
||||
impl_cast::impl_setup!();
|
||||
impl_cast::impl_cast!(GoogleHomeDevice, OnOff);
|
||||
impl_cast::impl_cast!(GoogleHomeDevice, Scene);
|
||||
|
||||
pub trait OnOff: std::fmt::Debug + Sync + Send + 'static {
|
||||
#[impl_cast::device_trait]
|
||||
pub trait OnOff {
|
||||
fn is_command_only(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
@@ -28,7 +25,8 @@ pub trait OnOff: std::fmt::Debug + Sync + Send + 'static {
|
||||
fn set_on(&mut self, on: bool) -> Result<(), ErrorCode>;
|
||||
}
|
||||
|
||||
pub trait Scene: std::fmt::Debug + Sync + Send + 'static {
|
||||
#[impl_cast::device_trait]
|
||||
pub trait Scene {
|
||||
fn is_scene_reversible(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user