Sun Oct 6 10:17:54 EDT 2013

Buffered channels : again

Let's do this.
A buffered channel needs two ends.  How does that map into traits?

Probably two traits are needed, and a "constructor" returns an object
that supports two traits, but is exposed only one side through each

This doesn't seem to be the right approach:

    trait BufPort<T> {
        fn recv(&self) -> T;
    trait BufChan<T> {
        fn send(&self, T);
    struct WrappedStream<T> {
        p : Port<T>,
        c : Chan<T>,
    impl<T> BufPort<T> for WrappedStream<T> {
        fn recv(&self) -> T { self.p.recv() }

-> error: instantiating a type parameter with an incompatible type `T`, which does not fulfill `Send`

Need to modify the *endpoints* of a channel, not the channel type

Hmm.. Getting the same errors with this:

    trait BufPort<T> { fn _recv(&self) -> T; }
    trait BufChan<T> { fn _send(&self, T); }

    struct WrappedPort<T> { p : Port<T> }
    struct WrappedChan<T> { c : Chan<T> }

    impl<T> BufPort<T> for WrappedPort<T> {
        fn _recv(&self) -> T { self.p.recv() }
    impl<T> BufChan<T> for WrappedChan<T> {
        fn _send(&self, e:T) { self.c.send(e); }

Start simpler?

Looking around the docs, I ran into `SendDeferred'


It needs:
use std::rt::comm::SendDeferred;

It doesn't seem to solve the performance issue.

Go back to the prev buffer impl and figure out what the error means.

Check this:  "Implementation for ChanOne<T> where <T: Send>"
from http://static.rust-lang.org/doc/0.8/std/comm.html

The "Send" trait is mentioned here as a special trait, implemented by the compiler:

  "Other special traits include send, which is a trait that indicates
  the type is sendable"

So I misread.  This is not a channel constraint, but a sendable data

With annotation fixed:

    trait BufPort<T:Send> { fn recv(&self) -> T; }
    trait BufChan<T:Send> { fn send(&self, T); }

    struct WrappedPort<T> { p : Port<T> }
    struct WrappedChan<T> { c : Chan<T> }

    impl<T:Send> BufPort<T> for WrappedPort<T> {
        fn recv(&self) -> T { self.p.recv() }
    impl<T:Send> BufChan<T> for WrappedChan<T> {
        fn send(&self, e:T) { self.c.send(e); }