项目作者: bastion-rs

项目描述 :
Proc macro attributes for Bastion runtime.
高级语言: Rust
项目地址: git://github.com/bastion-rs/fort.git
创建时间: 2019-10-05T21:53:06Z
项目社区:https://github.com/bastion-rs/fort

开源协议:Other

下载


Fort

Fort is proc macro attribute crate for Bastion.

Usage

  1. [dependencies]
  2. fort = "0.4"
  3. bastion = "0.4"

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

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

Make your program fault-tolerant with fort:

  1. #[fort::root]
  2. async fn main(_: BastionContext) -> Result<(), ()> {
  3. loop {
  4. println!("Undying main!");
  5. panic!("Error")
  6. }
  7. }

You want to spawn multiple process

  1. #[fort::root(redundancy = 10)]
  2. async fn main(_: BastionContext) -> Result<(), ()> {
  3. loop {
  4. println!("Undying main!");
  5. panic!("Error")
  6. }
  7. }

Example TCP Server

  1. use std::io::Write;
  2. use std::net::TcpListener;
  3. #[fort::root]
  4. async fn main(_: BastionContext) -> Result<(), ()> {
  5. let listener = TcpListener::bind("127.0.0.1:2278").unwrap();
  6. println!("TCP server started at 127.0.0.1:2278");
  7. for stream in listener.incoming() {
  8. thread::spawn(|| {
  9. let mut stream = stream.unwrap();
  10. stream.write_all(b"Hello World\r\n").unwrap();
  11. panic!("Fail in thread!");
  12. });
  13. panic!("Fail in event loop");
  14. }
  15. Ok(())
  16. }