comparison rust/src/sensor.rs @ 631:c57821a60e51 rust

rust work in progress ?
author Matt Johnston <matt@ucc.asn.au>
date Sat, 06 Jul 2019 18:28:34 +0800
parents f3e39e2107fd
children bde302def78e
comparison
equal deleted inserted replaced
630:7e9041534891 631:c57821a60e51
1 extern crate tokio_core;
2 extern crate futures;
3 extern crate futures_cpupool;
4 extern crate regex; 1 extern crate regex;
2
3 use actix::prelude::*;
5 4
6 use std::time::Duration; 5 use std::time::Duration;
7 use std::io; 6 use std::io;
8 use std::fs::File; 7 use std::fs::File;
9 use std::io::{Read,BufReader,BufRead}; 8 use std::io::{Read,BufReader,BufRead};
16 use tokio_core::reactor::Handle; 15 use tokio_core::reactor::Handle;
17 use futures::Stream; 16 use futures::Stream;
18 use types::*; 17 use types::*;
19 use ::Config; 18 use ::Config;
20 19
21 pub trait Sensor { 20 pub struct OneWireSensor {
22 fn stream(&self, handle: &Handle) -> Box<Stream<Item=Readings, Error=TemplogError>>; 21 config: Config,
22 fridge: Recipient<Readings>,
23 } 23 }
24 24
25 #[derive(Clone)] 25 impl Actor for OneWireSensor {
26 pub struct OneWireSensor { 26 type Context = Context<Self>;
27 config: Config,
28 } 27 }
29 28
30 impl OneWireSensor { 29 impl OneWireSensor {
31 pub fn new(config: &Config) -> Self { 30 pub fn new(config: &Config, fridge: Recipient<Readings>) -> Self {
32 OneWireSensor { 31 OneWireSensor {
33 config: config.clone(), 32 config: config.clone(),
34 } 33 }
35 } 34 }
36 35