Extern crate `crossbeam_utils` is private

I am somewhat baffled. I am trying to compile and run the code from the crossbeam::thread example at the top of the page here. I believe I have added the correct headers to use crossbeam. My code looks like this:
extern crate crossbeam;
use crossbeam::crossbeam_utils::thread;

    fn main() {
    
    let people = vec![
        "Alice".to_string(),
        "Bob".to_string(),
        "Carol".to_string(),
    ];
    
    thread::scope(|s| {
        for person in &people {
            s.spawn(move |_| {
                println!("Hello, {}!", person);
            });
        }
    }).unwrap();
    }

but I get an error that reads:

**error[E0603]** **: extern crate `crossbeam_utils` is private**

**-->** src/main.rs:3:16

**|**

**3** **|** use crossbeam::crossbeam_utils::thread;

**|** **^^^^^^^^^^^^^^^**

**error** **: aborting due to previous error**

**For more information about this error, try `rustc --explain E0603`.**

**error:** Could not compile `test-crossbeam`.

This doesn't seem to be googleable. Any ideas?

Sorry for the format error - the headers should be included in the program block.

the crate crossbeam and the crate crossbeam_utils are different. One way to solve this is by adding crossbeam-utils = "0.6.6" in your Cargo.toml, and then read this:

https://docs.rs/crossbeam-utils/0.6.6/crossbeam_utils/thread/index.html

Thanks, that was it. Dumb beginner mistake. I though that crossbeam was pulling the utils in as well. I really appreciate your help! It is great to get unstuck.

1 Like

crossbeam does pull in the utils, but it then re-exports the contents at the top level rather than exposing it as a submodule. So use crossbeam::thread and use crossbeam_utils::thread are actually the same thing.

This also explains why the example is a little confusing - when you re-export something from another crate, it retains the original doc comments, including examples. So despite that example showing up in crossbeam's docs, it's actually taken from crossbeam_utils.

2 Likes

Ah, that helps too. I appreciate it.