1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//!
//! Name constructors for code generation by `join!` macro.
//!
use ;
use format_ident;
///
/// Constructs name for variable with given index.
///
///
/// Constructs step result name using given index.
///
///
/// Constructs result name with given index.
///
///
/// Constructs thread builder name with given index.
///
///
/// Constructs inspect function name.
///
///
/// Constructs `tokio::spawn` wrapper function name.
///
///
/// Constructs results name.
///
///
/// Constructs handler name.
///
///
/// Constructs internal value name with no index.
///
///
/// Constructs result wrapper in order to be used when expression is block.
///
///
/// Constructs thread builder fn name. This function will generate thread builder with specified name.
/// This name will be displayed as result of thread::current().name().unwrap() or
/// in case of thread's panic.
///
/// # Example:
/// ```
/// extern crate join;
///
/// use std::thread;
/// use join::join_spawn;
///
/// join_spawn! {
/// Ok::<_, ()>("hello world") |> |value| {
/// println!("{}", thread::current().name().unwrap()); // main_join_0
/// value
/// }
/// };
/// ```
/// In runtime thread's name will be constructed from name of parent thread and join_%branch_index%.
///
/// # Example with several branches:
/// ```
/// extern crate join;
///
/// use std::thread;
///
/// use join::try_join_spawn;
///
/// fn current_thread_name() -> String {
/// thread::current().name().unwrap().to_owned()
/// }
///
/// fn print_branch_thread_name(index: &Result<usize, ()>) {
/// println!("Branch: {}. Thread name: {}.", index.unwrap(), current_thread_name());
/// }
///
/// let _ = try_join_spawn! {
/// Ok(0) ?? print_branch_thread_name,
/// Ok(1) ?? print_branch_thread_name,
/// try_join_spawn! {
/// Ok(2) ?? print_branch_thread_name,
/// try_join_spawn! {
/// Ok(3) ?? print_branch_thread_name,
/// }
/// }
/// }.unwrap();
///
/// // Branch: 0. Thread name: main_join_0.
/// // Branch: 1. Thread name: main_join_1.
/// // Branch: 2. Thread name: main_join_2_join_0.
/// // Branch: 3. Thread name: main_join_2_join_1_join_0.
/// // Order could be different.
/// ```
///