6 releases (3 breaking)

0.4.0 Dec 21, 2020
0.3.0 Dec 9, 2019
0.2.1 Dec 9, 2019
0.2.0 Oct 28, 2019
0.1.1 Oct 6, 2019

#532 in Procedural macros

Apache-2.0/MIT

14KB
73 lines

Fort

Fort is proc macro attribute crate for Bastion.

Usage

[dependencies]
fort = "0.4"
bastion = "0.4"

You can directly use fort to load work onto the root supervisor with:

#[fort::root]
async fn main(_: BastionContext) -> Result<(), ()> {
    println!("Running in Bastion runtime!");
    Ok(())
}

Make your program fault-tolerant with fort:

#[fort::root]
async fn main(_: BastionContext) -> Result<(), ()> {
    loop {
        println!("Undying main!");
        panic!("Error")
    }
}

You want to spawn multiple process

#[fort::root(redundancy = 10)]
async fn main(_: BastionContext) -> Result<(), ()> {
    loop {
        println!("Undying main!");
        panic!("Error")
    }
}

Example TCP Server

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(())
}

Dependencies

~1.5MB
~37K SLoC