Proposal: New channels for Rust's standard library

Note how beautifully symmetrical Sender and Receiver now are.

impl<T> Sender<T> {
    fn send(&self, t: T) -> Result<(), SendError<T>>;
}

impl<T> Receiver<T> {
    fn recv(&self) -> Result<T, RecvError>;
}

Just a random "accidental" observation, but this is "wrong". Send and receive should not be symmetric, they should be dual, the same way as Iterator and Observer are duals:

http://csl.stanford.edu/~christos/pldi2010.fit/meijer.duality.pdf

So, the signatures should be like this:

impl<T> Sender<T> {
    fn send(&self, t: Option<T>);
}

impl<T> Receiver<T> {
    fn recv(&self) -> Option<T>;
}

2 Likes