Skip to Content

Coding

PRIZM is a low-code platform that allows you to build applications without writing code. However, if you are a developer, you can also write code to extend the functionality of your applications.

Prerequisites

  • Basic knowledge of Rust
  • A coding IDE or the online code Editor

The PRIZM Imports

The code node uses some imports to interact with the PRIZM platform.

#[derive(Debug, Clone)] pub enum DataType { Bool(bool), Int(i32), Float(f64), String(String), Bytes(Vec<u8>), // used for DB stuff... Vec(Vec<DataType>), Map(HashMap<String, DataType>), } pub type DbMap<'a> = Arc<Mutex<HashMap<&'a str, DataType>>>; pub type IOMap<'a> = HashMap<&'a str, DataType>; pub type ConstMap<'a> = HashMap<&'a str, &'a str>; use tokio::sync::mpsc::{Receiver, Sender}; pub type SenderMap<'a> = HashMap<&'a str, Sender<DataType>>; pub type ReceiverMap<'a> = HashMap<&'a str, Receiver<DataType>>;

The Code Node

The basic structure of the code node is as follows:

pub async fn $FUNC_NAME$<'a>( db: &prizm::DbMap<'a>, input: &prizm::IOMap<'a>, constants: &prizm::ConstMap<'a>, ) -> prizm::Result<prizm::IOMap<'a>> { let temp = input.get("temp").ok_or(prizm::Error::from("not found"))?; println!("Temperature: {:?}", temp); return Ok(prizm::IOMap::from([("average_temp", temp.clone())])); }

The Actor Code Node

The actor code node is a more complex version of the code node that allows you to run local memory, state management, select when to listen to the input, and when to send the output. The default function signature is as follows:

pub async fn $FUNC_NAME$<'a>( db: &prizm::DbMap<'a>, mut receiver_map: prizm::ReceiverMap<'a>, sender_map: &prizm::SenderMap<'a>, constants: &prizm::ConstMap<'a>, ) { println!("Actor Code prefab"); loop { println!("Running actor code..."); } }

Now with the basic structure in place, you can start writing your code.

Caveats

  • The code should not have any imports outside the function declaration, if the code requires any imports, import them inside the function.
  • Make sure the function signature is $FUNC_NAME$, or this will break the code during compilation.
Last updated on