annotate rust/src/sensor.rs @ 587:646f03870762 rust

trying rust
author Matt Johnston <matt@ucc.asn.au>
date Wed, 14 Dec 2016 00:15:14 +0800
parents
children 038734052b20
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
587
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 use std::any::Any;
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 use robots::actors::{Actor, ActorSystem, ActorCell, ActorContext, Props};
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 pub struct Sensor {
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 }
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 impl Actor for Sensor {
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 fn receive(&self, message: Box<Any>, context: ActorCell) {
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 if let Ok(message) = Box::<Any>::downcast::<String>(message) {
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 println!("Sensor message! {}", message);
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 } else {
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 println!("Sensor message!");
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 }
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 }
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 }
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 impl Sensor {
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 pub fn new(_dummy: ()) -> Sensor {
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 Sensor {}
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 }
646f03870762 trying rust
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 }