Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SharedChan in Tasks and Communication Tutorial #9573

Closed
simao opened this issue Sep 27, 2013 · 3 comments
Closed

SharedChan in Tasks and Communication Tutorial #9573

simao opened this issue Sep 27, 2013 · 3 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@simao
Copy link

simao commented Sep 27, 2013

Hello,

I am reading the Rust Tasks and Communication Tutorial and I am trying to run the following code:

use std::uint;
use std::comm;

fn main() {
    let (port, chan) = stream();
    let chan = SharedChan::new(chan);

    for uint::range(0, 3) |init_val| {
        // Create a new channel handle to distribute to the child task
        let child_chan = chan.clone();

        do spawn {
            child_chan.send(init_val);
        }
    }

    let result = port.recv() + port.recv() + port.recv();
}

But I get the following error:

test.rs:8:15: 8:30 error: unresolved name
test.rs:8     let chan = SharedChan::new(chan);
                         ^~~~~~~~~~~~~~~

I thought SharedChan was defined in std::comm ?

Thanks

@metajack
Copy link
Contributor

It is, but you have to use std::com::SharedChan; or use it like let chan = comm::SharedChan::new(chan);.

Tutorial will need fixing of course.

@simao
Copy link
Author

simao commented Sep 28, 2013

Ah thanks, that works!

Just checked the markdown source for the tutorial and it includes:

# use std::task::spawn;
# use std::comm::{stream, SharedChan};

But that's not rendered on the html version.

On Fri, Sep 27, 2013 at 8:33 PM, Jack Moffitt notifications@git.luolix.topwrote:

It is, but you have to use std::com::SharedChan; or use it like let chan
= comm::SharedChan::new(chan);.

Tutorial will need fixing of course.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9573#issuecomment-25271015
.

@wting
Copy link
Contributor

wting commented Jan 12, 2014

This can be closed, the following code is from the tutorial and works as expected (without explicit imports):

fn main() {
    // single sender and receiver
    let (port, chan): (Port<int>, Chan<int>) = Chan::new();
    do spawn {
        chan.send(5);
    }

    println!("{:d}", port.recv());

    // multiple senders
    let (port, chan) = SharedChan::new();

    for i in range(0, 3) {
        let child_chan = chan.clone();
        do spawn {
            child_chan.send(i);
        }
    }

    println!("{:d} {:d} {:d}", port.recv(), port.recv(), port.recv());
}

flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 6, 2022
… r=dswij

lint nested patterns and slice patterns in `needless_borrowed_reference`

Now lints in positions other than top level, e.g. `Some(&ref a)`. Or patterns are excluded as that can cause issues

Slice patterns of `ref`s are now linted, e.g. `&[ref a, ref b]`. An easy one to walk into as you might expect that to match against a slice you should use `&[]`,  then to get around a `cannot move out of type [T]` error you apply a `ref`

changelog: [`needless_borrowed_reference`]: lint nested patterns and slice patterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

4 participants