#macro #time-series #river #water-system

macro nadi_plugin

使用 nadi_core 编写 nadi_system 插件的宏库

1 个不稳定版本

0.1.0 2024 年 8 月 9 日

132地理空间 中排名

Download history 73/week @ 2024-08-09

73 每月下载量

GPL-3.0-only

17KB
231

Nadi 系统插件进程宏

该包包含 Rust 中 nadi 系统插件开发的必要宏。

插件可以在不使用宏的情况下开发,但这使得它更容易,且错误更少。

示例插件

Cargo.toml:

[package]
name = "example_plugin"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
anyhow = "1.0.86"
nadi_core = "0.2.0"
nadi_functions = "0.1.0"

src/lib.rs:

use nadi_functions::nadi_plugin;

#[nadi_plugin]
mod example {
    use nadi_core::{attributes::AsValue, Network, NodeInner};
    use nadi_functions::nadi_func;

    /// Print the given attr of the node as string.
    ///
    /// This is a basic node funtion, the purpose of this function is
    /// to demonstrate how node functions can be written. But it might
    /// be useful in some cases.
    #[nadi_func]
    fn print_attr(node: &mut NodeInner, attr: String, key: bool) {
        println!(
            "{}{}",
            if key { &attr } else { "" },
            node.attr(&attr).into_string().unwrap_or_default()
        );
    }

    /// List all the attributes on the node
    #[nadi_func]
    fn list_attr(node: &mut NodeInner) {
        println!("{}: {}", node.name(), node.attributes().join(", "));
    }
	
    /// Print the given attr of all the nodes in a network
    #[nadi_func]
    fn print_net_attr(net: &mut Network, attr: String) {
        for node in net.nodes() {
            let node = node.borrow();
            println!(
                "{}: {}",
                node.name(),
                node.attr(&attr).into_string().unwrap_or_default()
            );
        }
    }

依赖项

~285–740KB
~18K SLoC