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
//!
//! Name constructors for code generation by `union!` macro.
//!
use Ident;
use format_ident;
///
/// Constructs name for variable with given index. For internal usage.
///
///
/// Constructs step result name using given index. For internal usage.
///
///
/// Constructs result name with given index. For internal usage.
///
///
/// Constructs thread builder name with given index. For internal usage.
///
///
/// Constructs inspect function name - async or not. For internal usage.
///
///
/// Constructs `tokio::spawn` wrapper function name - async or not. For internal usage.
///
///
/// Constructs result wrapper in order to be used when first step expression is block. For internal usage.
///
///
/// Constructs thread name with given index. This name will be displayed as result of thread::current().name().unwrap() or
/// in case of thread's panic.
/// ```
/// extern crate union;
///
/// use std::thread;
/// use union::union_spawn;
///
/// fn main() {
/// union_spawn! {
/// Ok::<_, ()>("hello world") |> |value| {
/// println!("{}", thread::current().name().unwrap()); // main_union_0
/// value
/// }
/// };
/// }
/// ```
/// In runtime thread's name will be constructed from {(name of parent thread (if it's `Some`) + `_`) or `` (if it's None)}union_{index of branch (starting from 0)}.
///
/// Example code with many branches.
/// ```
/// extern crate union;
///
/// use std::thread;
///
/// use union::union_spawn;
///
/// fn get_current_thread_name() -> String {
/// thread::current().name().unwrap().to_owned()
/// }
///
/// fn print_branch_thread_name(index: &Result<usize, ()>) {
/// println!("Branch: {}. Thead name: {}.", index.unwrap(), get_current_thread_name());
/// }
///
/// fn main() {
/// let _ = union_spawn! {
/// Ok(0) ?> print_branch_thread_name,
/// Ok(1) ?> print_branch_thread_name,
/// union_spawn! {
/// Ok(2) ?> print_branch_thread_name,
/// union_spawn! {
/// Ok(3) ?> print_branch_thread_name,
/// }
/// }
/// }.unwrap();
/// }
///
/// // Branch: 0. Thead name: main_union_0.
/// // Branch: 1. Thead name: main_union_1.
/// // Branch: 2. Thead name: main_union_2_union_0.
/// // Branch: 3. Thead name: main_union_2_union_1_union_0.
/// // Order could be different.
/// ```
///