fort

Crates.iofort
lib.rsfort
version0.4.0
sourcesrc
created_at2019-10-05 22:03:06.466427
updated_at2020-12-21 11:00:52.762688
descriptionProc macro attributes for Bastion runtime
homepagehttps://github.com/bastion-rs/fort
repositoryhttps://github.com/bastion-rs/fort
max_upload_size
id170237
size42,286
Jeremy Lempereur (o0Ignition0o)

documentation

README

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(())
}
Commit count: 27

cargo fmt