Mercurial > templog
changeset 590:dccd8504aa38 rust
it runs
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 21 Dec 2016 21:40:32 +0800 |
parents | f2508125adf1 |
children | 4a944663fa8d |
files | rust/Cargo.lock rust/Cargo.toml rust/src/main.rs rust/src/sensor.rs |
diffstat | 4 files changed, 26 insertions(+), 307 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/Cargo.lock Wed Dec 21 08:16:13 2016 +0800 +++ b/rust/Cargo.lock Wed Dec 21 21:40:32 2016 +0800 @@ -4,16 +4,6 @@ dependencies = [ "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-tls 0.1.0 (git+https://github.com/tokio-rs/tokio-tls)", -] - -[[package]] -name = "advapi32-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -22,42 +12,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "bitflags" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] name = "cfg-if" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "core-foundation" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "core-foundation-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crypt32-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "futures" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -66,15 +25,6 @@ ] [[package]] -name = "gdi32-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "kernel32-sys" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -84,11 +34,6 @@ ] [[package]] -name = "lazy_static" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] name = "lazycell" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -99,14 +44,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "libressl-pnacl-sys" -version = "2.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "log" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -164,58 +101,6 @@ ] [[package]] -name = "openssl" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.7.17 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "openssl-sys" -version = "0.7.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "libressl-pnacl-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "openssl-verify" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "openssl 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "pkg-config" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "pnacl-build-helper" -version = "1.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "rustc_version" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -224,54 +109,11 @@ ] [[package]] -name = "schannel" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "secur32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "scoped-tls" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "secur32-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "security-framework" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "security-framework-sys" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "semver" version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -282,14 +124,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "tempdir" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "tokio-core" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -302,30 +136,6 @@ ] [[package]] -name = "tokio-tls" -version = "0.1.0" -source = "git+https://github.com/tokio-rs/tokio-tls#3d49e52e54123686598d7b953727743a323a5d4a" -dependencies = [ - "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-verify 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "schannel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "user32-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "void" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -350,43 +160,22 @@ ] [metadata] -"checksum advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e06588080cb19d0acb6739808aafa5f26bfb2ca015b2b6370028b44cf7cb8a9a" "checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3" -"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" -"checksum core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "20a6d0448d3a99d977ae4a2aa5a98d886a923e863e81ad9ff814645b6feb3bbd" -"checksum core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "05eed248dc504a5391c63794fe4fb64f46f071280afaa1b73308f3c0ce4574c5" -"checksum crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e34988f7e069e0b2f3bfc064295161e489b2d4e04a2e4248fb94360cdf00b4ec" "checksum futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bad0a2ac64b227fdc10c254051ae5af542cf19c9328704fd4092f7914196897" -"checksum gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0912515a8ff24ba900422ecda800b52f4016a56251922d397c576bf92c690518" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b" "checksum lazycell 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce12306c4739d86ee97c23139f3a34ddf0387bbf181bc7929d287025a8c3ef6b" "checksum libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a51822fc847e7a8101514d1d44e354ba2ffa7d4c194dcab48870740e327cac70" -"checksum libressl-pnacl-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "cbc058951ab6a3ef35ca16462d7642c4867e6403520811f28537a4e2f2db3e71" "checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" "checksum mio 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "410a1a0ff76f5a226f1e4e3ff1756128e65cd30166e39c3892283e2ac09d5b67" "checksum miow 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d5bfc6782530ac8ace97af10a540054a37126b63b0702ddaaa243b73b5745b9a" "checksum net2 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)" = "5edf9cb6be97212423aed9413dd4729d62b370b5e1c571750e882cebbbc1e3e2" "checksum nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d95c5fa8b641c10ad0b8887454ebaafa3c92b5cd5350f8fc693adafd178e7b" -"checksum openssl 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b11754cb6c81bb9e62faaf0eb6d94dde2aab0928c04db5078b74242880f35eb1" -"checksum openssl-sys 0.7.17 (registry+https://github.com/rust-lang/crates.io-index)" = "89c47ee94c352eea9ddaf8e364be7f978a3bb6d66d73176572484238dd5a5c3f" -"checksum openssl-verify 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8d58c0494a0a51babcc2c30b19f54dfffcca7c4af5adb557ae078ca63ce933d4" -"checksum pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8cee804ecc7eaf201a4a207241472cc870e825206f6c031e3ee2a72fa425f2fa" -"checksum pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "61c9231d31aea845007443d62fcbb58bb6949ab9c18081ee1e09920e0cf1118b" -"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" -"checksum schannel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "167852e03fcd0029c3ddebb5afb0715b2996f6e262b2c2aceaa7cd84edd4b158" "checksum scoped-tls 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f417c22df063e9450888a7561788e9bd46d3bb3c1466435b4eccb903807f147d" -"checksum secur32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f412dfa83308d893101dd59c10d6fda8283465976c28c287c5c855bf8d216bc" -"checksum security-framework 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "52186fcf3b391c9f0ccdce9a2ac708f7cc81b3f89e149b34bd9279fb1b23f9fa" -"checksum security-framework-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c84067e6297c1f09514a8666d8bbc1268817ec4a6c0f30f12f6201e1f34bd2a1" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" "checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23" -"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" "checksum tokio-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "06f40e15561569e24dab3dcf270c0bb950195b84dbed591dfb6591e28c9b9cff" -"checksum tokio-tls 0.1.0 (git+https://github.com/tokio-rs/tokio-tls)" = "<none>" -"checksum user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ef4711d107b21b410a3a974b1204d9accc8b10dad75d8324b5d755de1617d47" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
--- a/rust/Cargo.toml Wed Dec 21 08:16:13 2016 +0800 +++ b/rust/Cargo.toml Wed Dec 21 21:40:32 2016 +0800 @@ -6,5 +6,4 @@ [dependencies] futures = "0.1.6" tokio-core = "0.1.1" -tokio-tls = { git = "https://github.com/tokio-rs/tokio-tls" }
--- a/rust/src/main.rs Wed Dec 21 08:16:13 2016 +0800 +++ b/rust/src/main.rs Wed Dec 21 21:40:32 2016 +0800 @@ -1,75 +1,10 @@ -#![feature(conservative_impl_trait)] extern crate tokio_core; extern crate futures; -use std::time::Duration; -use std::cell::RefCell; -use std::io::{self, Read, Write}; - -use tokio_core::reactor::Interval; use tokio_core::reactor::Core; -use tokio_core::reactor::Handle; -use futures::{Future, failed, Poll, Async, Stream}; - -pub struct Reading { - name: String, - value: Option<f32>, -} - -pub type Readings = Vec<Reading>; - -pub struct Sensor { - current: f32, -} - -struct Periodic<T> { - interval: Interval, -} - -trait Ticker { - type TickItem; - fn tick(&self) -> Self::TickItem; -} - -impl<T: Ticker> Stream for Periodic<T> { - type Item = T::TickItem; - type Error = io::Error; +use futures::Stream; - fn poll(&mut self) -> Poll<Option<Self::Item>, io::Error> { - self.interval.poll().map(|a| { - if let Async::Ready(t) = a { - Async::Ready(self.tick()) - } else { - a - } - }) - } -} - -impl Sensor { - - fn step(&mut self) -> Readings { - let mut r = Vec::new(); - self.current = self.current + 0.1; - r.push(Reading { name: "aaa".to_string(), value: Some(self.current) }); - r - } - - pub fn new() -> Sensor { - Sensor { current: 22.0 } - } - - pub fn run(handle: &Handle) -> Box<Stream<Item=Readings, Error=io::Error>> { - let mut s = Sensor::new(); - - let dur = Duration::from_millis(400); - Interval::new(dur, handle).unwrap().map(move |()| { - println!("each one"); - // TODO read the sensor here - s.step() - } ) - } -} +mod sensor; fn main() { println!("Wort Templog"); @@ -77,18 +12,10 @@ let mut core = Core::new().unwrap(); let handle = core.handle(); - let s = Sensor::run(&handle); - - let mut re = Readings::new(); + let s = sensor::Sensor::run(&handle); let h = s.for_each(|r| { - re = r; - for rx in &re { - match rx.value { - Some(x) => println!("re is {} {}", rx.name, x), - None => println!("re is {} broken", rx.name), - } - }; + println!("readings {:?}", r); Ok(()) });
--- a/rust/src/sensor.rs Wed Dec 21 08:16:13 2016 +0800 +++ b/rust/src/sensor.rs Wed Dec 21 21:40:32 2016 +0800 @@ -2,39 +2,43 @@ extern crate futures; use std::time::Duration; -use std; -use std::cell::RefCell; +use std::io; use tokio_core::reactor::Interval; -use tokio_core::reactor::Core; use tokio_core::reactor::Handle; use futures::Stream; -use futures::Future; -pub struct Readings { - +#[derive(Debug)] +pub struct Reading { + name: String, + value: Option<f32>, } +pub type Readings = Vec<Reading>; + pub struct Sensor { + current: f32, } impl Sensor { - fn step(self) -> Readings { - return Readings {} - } - - pub fn new() -> Sensor { - Sensor {} + fn step(&mut self) -> Readings { + let mut r = Vec::new(); + self.current = self.current + 0.1; + r.push(Reading { name: "aaa".to_string(), value: Some(self.current) }); + r } - pub fn run(handle: &Handle) -> Box<Future<Item=Readings, Error = std::io::Error>> { - let s = Sensor::new(); + fn new() -> Self { + Sensor { current: 22.0 } + } - Interval::new(Duration::from_millis(400), handle).map(|()| { - println!("each one"); - // s.step() - Readings {} + pub fn run(handle: &Handle) -> Box<Stream<Item=Readings, Error=io::Error>> { + let mut s = Sensor::new(); + + let dur = Duration::from_millis(400); + Interval::new(dur, handle).unwrap().map(move |()| { + s.step() }).boxed() } }