1 use std::collections::HashSet; 2 3 use rayon::prelude::*; 4 use rayon::*; 5 6 #[test] named_threads()7fn named_threads() { 8 ThreadPoolBuilder::new() 9 .thread_name(|i| format!("hello-name-test-{}", i)) 10 .build_global() 11 .unwrap(); 12 13 const N: usize = 10000; 14 15 let thread_names = (0..N) 16 .into_par_iter() 17 .flat_map(|_| ::std::thread::current().name().map(str::to_owned)) 18 .collect::<HashSet<String>>(); 19 20 let all_contains_name = thread_names 21 .iter() 22 .all(|name| name.starts_with("hello-name-test-")); 23 assert!(all_contains_name); 24 } 25