https://github.com/bastion-rs/fort
Proc macro attributes for Bastion runtime.
https://github.com/bastion-rs/fort
bastion fault-tolerance fort proc-macro proc-macro-attributes rust rust-lang
Last synced: 9 months ago
JSON representation
Proc macro attributes for Bastion runtime.
- Host: GitHub
- URL: https://github.com/bastion-rs/fort
- Owner: bastion-rs
- License: apache-2.0
- Created: 2019-10-05T21:53:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-24T21:31:59.000Z (about 4 years ago)
- Last Synced: 2025-04-19T11:17:21.676Z (10 months ago)
- Topics: bastion, fault-tolerance, fort, proc-macro, proc-macro-attributes, rust, rust-lang
- Language: Rust
- Size: 37.1 KB
- Stars: 49
- Watchers: 4
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Fort
Fort is proc macro attribute crate for Bastion.
## Usage
```toml
[dependencies]
fort = "0.4"
bastion = "0.4"
```
You can directly use fort to load work onto the root supervisor with:
```rust
#[fort::root]
async fn main(_: BastionContext) -> Result<(), ()> {
println!("Running in Bastion runtime!");
Ok(())
}
```
Make your program fault-tolerant with `fort`:
```rust
#[fort::root]
async fn main(_: BastionContext) -> Result<(), ()> {
loop {
println!("Undying main!");
panic!("Error")
}
}
```
You want to spawn multiple process
```rust
#[fort::root(redundancy = 10)]
async fn main(_: BastionContext) -> Result<(), ()> {
loop {
println!("Undying main!");
panic!("Error")
}
}
```
# Example TCP Server
```rust
use std::io::Write;
use std::net::TcpListener;
#[fort::root]
async fn main(_: BastionContext) -> Result<(), ()> {
let listener = TcpListener::bind("127.0.0.1:2278").unwrap();
println!("TCP server started at 127.0.0.1:2278");
for stream in listener.incoming() {
thread::spawn(|| {
let mut stream = stream.unwrap();
stream.write_all(b"Hello World\r\n").unwrap();
panic!("Fail in thread!");
});
panic!("Fail in event loop");
}
Ok(())
}
```