3 releases

new 0.0.4 Nov 28, 2024
0.0.3 Nov 28, 2024
0.0.2 Nov 22, 2024

#1610 in Procedural macros

Download history 122/week @ 2024-11-18 293/week @ 2024-11-25

415 downloads per month
Used in 3 crates (via juiz_sdk)

WTFPL license

80KB
1K SLoC

juizの機能要素開発のためのヘルパーマクロの定義のためのパッケージ

このパッケージはjuiz_sdkから使われる、機能要素定義用のマクロのパッケージです。

使い方

プロセス、コンテナ、コンテナプロセスおよびコンポーネントの実体の関数定義に宣言型マクロとして使います。

プロセスの例

#[juiz_process(
    description = "This is listener process."
    arguments = {
        default = {
            arg1 = "Hello, Juiz!"
        }
        description = {
            arg1 = "This message is printed."
        }
    }
)]
fn listener(arg1: String) -> JuizResult<Capsule> {
    log::trace!("listener({:}) called", arg1);
    println!("listener: {:}", arg1);
    return Ok(jvalue!("Hello World").into());
}

コンテナの例

use juiz_sdk::prelude::*;
#[repr(Rust)]
pub struct ExampleContainer {
    pub value: i64
}

#[juiz_container(
    description = "This is description for container."
    arguments = {
        default = {
            initial_value = 0
        }
        description = {
            initial_value = "Default value of container included value."
        }
    }
)]
fn example_container(initial_value: i64) -> JuizResult<Box<ExampleContainer>> {
    Ok(Box::new(ExampleContainer{value:initial_value}))
}

コンテナプロセスの例

コンテナプロセス定義のためのマクロ

Examples

use example_container::ExampleContainer;
use juiz_sdk::prelude::*;

#[juiz_container_process(
    container_type = "example_container"
    description = "Container Process for example_container. This process will add given value to container."
    arguments = {
        default = {
            arg1 = 1
        }
    }
)]
fn increment_function(container: &mut ContainerImpl<ExampleContainer>, arg1: i64) -> JuizResult<Capsule> {
    container.value = container.value + arg1;
    return Ok(jvalue!(container.value).into());
}

コンポーネントの例

use juiz_sdk::prelude::*;
#[juiz_component_process]
fn example_component_increment(arg1: i64) -> JuizResult<Capsule> {
    log::trace!("increment_process({:?}) called", arg1);
    return Ok(jvalue!(arg1+1).into());
}

#[repr(Rust)]
pub struct ExampleComponentContainer {
    pub value: i64
}

#[juiz_component_container]
fn example_component_container(initial_value: i64) -> JuizResult<Box<ExampleComponentContainer>> {
    println!("example_component_container({initial_value}) called");
    Ok(Box::new(ExampleComponentContainer{value: initial_value}))
}

#[juiz_component_container_process( container_type = "example_component_container" )]
fn example_component_container_get(container: &mut ContainerImpl<ExampleComponentContainer>) -> JuizResult<Capsule> {
    println!("example_component_container_get()");
    Ok(jvalue!(container.value).into())
}

#[juiz_component_container_process( container_type = "example_component_container" )]
fn example_component_container_increment(container: &mut ContainerImpl<ExampleComponentContainer>) -> JuizResult<Capsule> {
    println!("example_component_container_increment()");
    container.value = container.value + 1;
    Ok(jvalue!(container.value).into())
}   

#[juiz_component_container_process( container_type = "example_component_container" 
   arguments = {
      default = {
        arg1 = 1
      }
   }
)]
fn example_component_container_add(container: &mut ContainerImpl<ExampleComponentContainer>, arg1: i64) -> JuizResult<Capsule> {
    println!("example_component_container_add({arg1})");
    container.value = container.value + arg1;
    Ok(jvalue!(container.value).into())
}

juiz_component_manifest!(
    component_name = "example_component"
    containers = {
        example_component_container = [
            example_component_container_get,
            example_component_container_increment,
            example_component_container_add
        ]
    }
    processes = [
        example_component_increment
    ]
);

Dependencies

~9MB
~135K SLoC