Skip to main content

interstice_cli/
example.rs

1use std::{fs::File, io::Write as _, path::Path};
2
3use interstice_core::{IntersticeError, Node};
4
5use crate::data_directory::data_file;
6
7pub async fn example(port: u32) -> Result<(), IntersticeError> {
8    let mut node = Node::new(&data_file(), port)?;
9    node.clear_logs().await.expect("Couldn't clear logs");
10    let hello_path = "../../target/wasm32-unknown-unknown/debug/hello.wasm";
11    let caller_path = "../../target/wasm32-unknown-unknown/debug/caller.wasm";
12    let graphics_path = "../../target/wasm32-unknown-unknown/debug/graphics.wasm";
13
14    if port != 8080 {
15        // Client
16        let _caller_schema = node.load_module_from_file(caller_path).await?.to_public();
17        let _graphics_schema = node.load_module_from_file(graphics_path).await?.to_public();
18    } else {
19        // Server
20        let hello_schema = node.load_module_from_file(hello_path).await?; //.to_public();
21        File::create("./hello_schema.toml")
22            .unwrap()
23            .write_all(&hello_schema.to_toml_string().unwrap().as_bytes())
24            .unwrap();
25    }
26
27    let node_schema = node.schema("MyNode".into()).await.to_public();
28    File::create("./node_schema.toml")
29        .unwrap()
30        .write_all(&node_schema.to_toml_string().unwrap().as_bytes())
31        .unwrap();
32
33    node.start().await?;
34    Ok(())
35}