Skip to content

std::Vec does not have the from_fn method described in the tutorial #21194

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

Closed
bandrei opened this issue Jan 15, 2015 · 1 comment
Closed

std::Vec does not have the from_fn method described in the tutorial #21194

bandrei opened this issue Jan 15, 2015 · 1 comment

Comments

@bandrei
Copy link

bandrei commented Jan 15, 2015

Info located at: http://doc.rust-lang.org/book/tasks.html

// Create a vector of ports, one for each child thread
let rxs = Vec::from_fn(3, |init_val| {
    let (tx, rx) = channel();
    spawn(move || {
        tx.send(some_expensive_computation(init_val));
    });
    rx
});

// Wait on each port, accumulating the results
let result = rxs.iter().fold(0, |accum, rx| accum + rx.recv() );

Looking at the source code in libcollections there doesn't seem to be such a method alltogether.

@steveklabnik
Copy link
Member

This would be fixed by #21152

The new way is (0..3).map(f).collect()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants