pantomime-rs / pantomime

MIT License
5 stars 1 forks source link

Consider associated types for Actor trait #5

Closed longshorej closed 5 years ago

longshorej commented 5 years ago

Investigate if there are any benefits to preferring associated types over type parameters. If it simplifies impl boilerplate it may be worth it.

(current)

pub trait Actor<M: 'static + Send> {
    fn receive(&mut self, message: M, context: &mut ActorContext<M>);

    fn receive_signal(&mut self, signal: Signal, context: &mut ActorContext<M>) {
        let _ = signal;

        let _ = context;
    }
}

vs possible alternative

pub trait Actor {
    type Msg: 'static + Send;

    fn receive(&mut self, message: self::Msg, context: &mut ActorContext<self::Msg>);

    fn receive_signal(&mut self, signal: Signal, context: &mut ActorContext<self::Msg>) {
        let _ = signal;

        let _ = context;
    }
}
longshorej commented 5 years ago

This has been done where appropriate.