No more cast_mut()
This commit is contained in:
@@ -56,7 +56,7 @@ pub trait Device: DeviceFulfillment {
|
||||
device
|
||||
}
|
||||
|
||||
async fn execute(&mut self, command: Command) -> Result<(), ErrorCode> {
|
||||
async fn execute(&self, command: Command) -> Result<(), ErrorCode> {
|
||||
DeviceFulfillment::execute(self, command.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -138,7 +138,7 @@ impl GoogleHome {
|
||||
let execution = command.execution.clone();
|
||||
async move {
|
||||
if let Some(device) = devices.get(id.as_str())
|
||||
&& let Some(device) = device.write().await.as_mut().cast_mut()
|
||||
&& let Some(device) = device.write().await.as_ref().cast()
|
||||
{
|
||||
if !device.is_online() {
|
||||
return (id, Ok(false));
|
||||
|
||||
@@ -501,7 +501,7 @@ pub fn traits(item: TokenStream) -> TokenStream {
|
||||
|
||||
Some(quote! {
|
||||
Command::#command_name {#(#parameters,)*} => {
|
||||
if let Some(t) = self.cast_mut() as Option<&mut dyn #ident> {
|
||||
if let Some(t) = self.cast() as Option<&dyn #ident> {
|
||||
t.#f_name(#(#parameters,)*) #asyncness #errors;
|
||||
serde_json::to_value(t.get_state().await?)?
|
||||
} else {
|
||||
@@ -528,7 +528,7 @@ pub fn traits(item: TokenStream) -> TokenStream {
|
||||
pub trait #fulfillment: Sync + Send {
|
||||
async fn sync(&self) -> Result<(Vec<Trait>, serde_json::Value), Box<dyn ::std::error::Error>>;
|
||||
async fn query(&self) -> Result<serde_json::Value, Box<dyn ::std::error::Error>>;
|
||||
async fn execute(&mut self, command: Command) -> Result<serde_json::Value, Box<dyn std::error::Error>>;
|
||||
async fn execute(&self, command: Command) -> Result<serde_json::Value, Box<dyn std::error::Error>>;
|
||||
}
|
||||
|
||||
#(#structs)*
|
||||
@@ -556,7 +556,7 @@ pub fn traits(item: TokenStream) -> TokenStream {
|
||||
Ok(state)
|
||||
}
|
||||
|
||||
async fn execute(&mut self, command: Command) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||
async fn execute(&self, command: Command) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||
let value = match command {
|
||||
#(#execute)*
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user