barley-proc

Crates.iobarley-proc
lib.rsbarley-proc
version0.2.0
sourcesrc
created_at2023-05-17 14:54:29.647842
updated_at2023-05-25 09:46:31.917447
descriptionA proc-macro crate for Barley
homepagehttps://github.com/panthios/barley
repositoryhttps://github.com/panthios/barley
max_upload_size
id867016
size21,120
Carlos Kieliszewski (carlosskii)

documentation

https://docs.rs/barley-proc

README

barley-proc

This crate provides the procedural macros for the barley workflow engine.

All functions from barley-proc are re-exported with barley-runtime. Since the runtime is essential anyway, this crate should not be imported directly. Use the barley-runtime crate instead.

Usage

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

cargo fmt