Skip to content

Sharing Channels in Rust #3928

@jhebus

Description

@jhebus

Hi,

I'm new to Rust and trying to figure out how to use it. In the following code i am trying to create some channels in main and then disperse them to some tasks, but the (0.4) compiler is telling me that i am not able to copy channels or ports. So,

*Is what i am trying to do possible
*Is there a better way

Thanks,

Paul

/-------------------------------------/

use pipes::;
use io::
;

fn recv_actor(b: Port<~str>) {

loop{
    let val = b.recv();
    println(#fmt("%s", val));
}

}

fn send_actor(a: Chan<~str>) {

loop{
    let readBytes = io::stdin().read_line();    
    a.send(readBytes);
}

}

fn main() {
let (a, b) = stream();

do task::spawn | move a|{ send_actor(a); }
do task::spawn | move b|{ recv_actor(b); }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions