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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*!
Framework for building Rust applications that run on [lunatic][1].
# Main concepts
The main abstraction in [lunatic][1] is a process. Contrary to operating system processes,
lunatic processes are lightweight and fast to spawn. They are designed for **massive**
concurrency. Like operating system processes, they are sandboxed. Each of them gets a separate
memory and they can't access the memory from other processes, not even through raw pointers.
If we want to exchange any information between process we need to do it through message passing.
This library makes processes feel native to the Rust language. They can be spawned from just a
function.
### Process types:
* **[`Process`]** - A process that can receive messages through a [`Mailbox`] or
[`Protocol`](protocol::Protocol).
* **[`AbstractProcess`](AbstractProcess)** - Abstracts state management and message/request
handling.
* **[`Supervisor`](supervisor::Supervisor)** - A process that can supervise others and re-spawn
them if they fail.
### Linking
Processes can be linked together. This means that if one of them fails, all linked ones will be
killed too.
To spawn a linked process use the [`spawn_link`] function.
### Process configuration
Spawn functions have a variant that takes a [`ProcessConfig`]. This configuration can be used
to set a memory or CPU limit on the newly spawned process. It can also be used to control file
and network access permissions of processes.
### Setup
To run the example you will first need to download the lunatic runtime by following the
installation steps in [this repository][1]. The runtime is just single executable and runs on
Windows, macOS and Linux. If you have already Rust installed, you can get it with:
```bash
cargo install lunatic-runtime
```
[Lunatic][1] applications need to be compiled to [WebAssembly][2] before they can be executed by
the runtime. Rust has great support for WebAssembly and you can build a lunatic compatible
application just by passing the `--target=wasm32-wasi` flag to cargo, e.g:
```bash
# Add the WebAssembly target
rustup target add wasm32-wasi
# Build the app
cargo build --release --target=wasm32-wasi
```
This will generate a .wasm file in the `target/wasm32-wasi/release/` folder inside your project.
You can now run your application by passing the generated .wasm file to Lunatic, e.g:
```ignore
lunatic run target/wasm32-wasi/release/<name>.wasm
```
#### Better developer experience
To simplify developing, testing and running lunatic applications with cargo, you can add a
`.cargo/config.toml` file to your project with the following content:
```toml
[build]
target = "wasm32-wasi"
[target.wasm32-wasi]
runner = "lunatic run"
```
or inside of your Cargo project just run:
```
lunatic init
```
This will automatically crate the file above.
Now you can just use the commands you were already familiar with, such as `cargo run`, `cargo test`
and cargo is going to automatically build your project as a WebAssembly module and run it inside
`lunatic`.
### Testing
Lunatic provides a [`macro@test`] macro to run your tests inside processes. Check out the [`tests`][3]
directory for examples.
[1]: https://github.com/lunatic-solutions/lunatic
[2]: https://webassembly.org/
[3]: https://github.com/lunatic-solutions/rust-lib/tree/main/tests
*/
pub use AbstractProcess;
pub use ProcessConfig;
pub use LunaticError;
pub use Process;
pub use ;
pub use *;
pub use test;
pub use ;
pub use ;
pub use Key as __StaticProcessLocalInner;
pub use ProcessLocal;
pub use ProcessName;
pub use Tag;
/// Implemented for all resources held by the VM.
/// Suspends the current process for `duration` of time.