| 0.2.0 |  | 
|---|---|
| 0.1.0 |  | 
| 0.0.1 |  | 
#5 在 #barley
每月下载量 48次
11KB
238 行
大麦-proc
此crate为大麦工作流引擎提供进程宏。
从 大麦-proc 中导出所有函数,并使用 大麦-runtime 进行导出。由于运行时是必需的,因此不应直接导入此crate。请使用 大麦-runtime crate。
用法
use barley_runtime::*;
use async_trait::async_trait;
use std::sync::Arc;
use tokio::sync::RwLock;
#[barley_action]
#[derive(Default)]
struct Print {
  message: String
}
impl Print {
  fn new(message: String) -> Self {
    // `Default` is required to set the internal
    // barley state.
    Self { message, ..Default::default() }
  }
}
#[barley_action]
#[async_trait]
impl Action for Print {
  async fn check(&self, ctx: Arc<RwLock<Context>>) -> Result<bool> {
    Ok(false)
  }
  async fn perform(&mut self, ctx: Arc<RwLock<Context>>) -> Result<Option<ActionOutput>> {
    println!("{}", self.message);
    Ok(None)
  }
  async fn rollback(&mut self, ctx: Arc<RwLock<Context>>) -> Result<()> {
    Ok(())
  }
}
依赖项
~310–760KB
~18K SLoC