Commit bb1b3927 authored by Constantin Berhard's avatar Constantin Berhard
Browse files

progress with TestableEvent

fun with the Box<Any> type
parent 78b08081
......@@ -18,15 +18,6 @@ pub struct Actors {
buzz: Box<Actor<bool>>,
}
/// Corresponds to the position of the respective actor in struct Actors.
/// It is used for testing, to check that the correct actor is activated.
#[derive(Copy,Clone,Debug,PartialEq,Eq)]
pub enum ActorType {
GreenLed,
Lock,
Buzz,
}
/// A [Situation] is something that can deal with all events coming in at a
/// particular time. It has access to the actors and can handle events by
/// using the [Environment]. When done, it has to return back all the actors,
......
struct BookKeeper;
use std::sync::mpsc::Receiver;
use testing::TestableEvent;
struct BookKeeper {
receiver: Receiver<Box<TestableEvent>>,
}
use std::fmt::Debug;
use brain::ActorType;
use testing::ActorType;
use testing::TestableEvent;
use std::boxed::Box;
use std::any::Any;
#[derive(Copy,Clone,Debug,PartialEq,Eq)]
struct ActorActed<T>
where T: PartialEq + Eq + Debug + Copy + Clone
pub struct ActorActed<T>
where T: PartialEq + Eq + Debug + Copy + Clone + Any
{
actor: ActorType,
act: T,
pub actor: ActorType,
pub act: T,
}
impl<T> TestableEvent for ActorActed<T>
where T: PartialEq + Eq + Debug + Copy + Clone
{}
where T: PartialEq + Eq + Debug + Copy + Clone + Any
{
fn obj_equals(&self, other: Box<Any>) -> bool {
match other.downcast::<ActorActed<T>>() {
Ok(other) => *self == *other,
Err(_) => false,
}
}
}
use std::fmt::Debug;
use std::cmp::Eq;
use std::any::Any;
trait TestableEvent: Debug + Eq {}
/// An event of some kind, that can be compared to other `TestableEvent`s for testing
/// and has a `Debug` implementation for human debugging with the logger.
pub trait TestableEvent: Debug + Any {
fn obj_equals(&self, other: Box<Any>) -> bool;
}
mod events;
/// Corresponds to the position of the respective actor in brain::Actors.
/// It is used for testing, to check that the correct actor is activated.
#[derive(Copy,Clone,Debug,PartialEq,Eq)]
pub enum ActorType {
GreenLed,
Lock,
Buzz,
}
pub mod events;
mod book_keeper;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment