Proc Macros for Nadi System Plugins
This crate contains the necessary macros for the nadi system plugin
development in rust.
The plugins can be developed without using the macros, but this makes
it easier, and less error prone.
Example Plugin:
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;
#[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()
);
}
#[nadi_func]
fn list_attr(node: &mut NodeInner) {
println!("{}: {}", node.name(), node.attributes().join(", "));
}
#[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()
);
}
}