Skip to content

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

Closed
@bandrei

Description

@bandrei

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions