From fc477d2d56c74587db81001e54a50ba5c4b7c399 Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Wed, 9 Dec 2020 10:49:34 +0100 Subject: [PATCH] Move Actuator into actor.rs --- src/actor.rs | 16 ++++++++++++++-- src/registries.rs | 1 - src/registries/actuators.rs | 29 ----------------------------- 3 files changed, 14 insertions(+), 32 deletions(-) delete mode 100644 src/registries/actuators.rs diff --git a/src/actor.rs b/src/actor.rs index c331874..24cda62 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -11,12 +11,15 @@ use futures::channel::mpsc; use futures_signals::signal::{Signal, MutableSignalCloned, MutableSignal, Mutable}; use crate::db::machine::MachineState; -use crate::registries::actuators::Actuator; use crate::config::Settings; use crate::error::Result; use crate::network::ActorMap; +pub trait Actuator { + fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()>; +} + pub type ActorSignal = Box + Unpin + Send>; pub struct Actor { @@ -92,8 +95,17 @@ impl Future for Actor { } } +pub struct Dummy; + +impl Actuator for Dummy { + fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()> { + println!("New state for dummy actuator: {:?}", state); + Box::pin(smol::future::ready(())) + } +} + pub fn load() -> Result<(ActorMap, Vec)> { - let d = Box::new(crate::registries::actuators::Dummy); + let d = Box::new(Dummy); let (tx, a) = Actor::wrap(d); let mut map = HashMap::new(); diff --git a/src/registries.rs b/src/registries.rs index 1cb9c85..5743b51 100644 --- a/src/registries.rs +++ b/src/registries.rs @@ -1,2 +1 @@ -pub mod actuators; pub mod sensors; diff --git a/src/registries/actuators.rs b/src/registries/actuators.rs deleted file mode 100644 index be561dd..0000000 --- a/src/registries/actuators.rs +++ /dev/null @@ -1,29 +0,0 @@ -use slog::Logger; - -use std::sync::Arc; -use smol::lock::RwLock; - -use std::pin::Pin; -use futures::ready; -use futures::prelude::*; -use futures::future::BoxFuture; -use futures::channel::mpsc; -use futures::task::{Context, Poll, Spawn}; -use futures_signals::signal::Signal; - -use crate::db::machine::MachineState; - -use std::collections::HashMap; - -pub trait Actuator { - fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()>; -} - -pub struct Dummy; - -impl Actuator for Dummy { - fn apply(&mut self, state: MachineState) -> BoxFuture<'static, ()> { - println!("New state for dummy actuator: {:?}", state); - Box::pin(smol::future::ready(())) - } -}