Skip to main content

std_native_table

Function std_native_table 

Source
pub fn std_native_table() -> Arc<NativeTable> 
Expand description

Default FFI table: print, clock, and Message make/unpack.

Pass this to crate::Runtime::with_natives (or with_natives_and_config) whenever the chunk emits the Message helpers or print / now_ms. Chunks that never CallNative can keep crate::NativeTable::empty.

Examples found in repository?
examples/ping_pong.rs (line 13)
9fn main() {
10    let chunk = samples::ping_pong();
11    let rt = match Runtime::with_natives_and_config(
12        chunk,
13        std_native_table(),
14        RuntimeConfig {
15            workers: 1,
16            quantum: 10_000,
17        },
18    ) {
19        Ok(rt) => rt,
20        Err(e) => {
21            eprintln!("runtime: {e}");
22            std::process::exit(1);
23        }
24    };
25    let Some(main) = rt.function_index("main") else {
26        eprintln!("missing main");
27        std::process::exit(1);
28    };
29    let handle = match rt.spawn(main, &[]) {
30        Ok(h) => h,
31        Err(e) => {
32            eprintln!("spawn: {e}");
33            std::process::exit(1);
34        }
35    };
36    let outcome = handle.join();
37    let metrics = rt.metrics();
38    rt.shutdown();
39
40    match outcome {
41        FlowOutcome::Completed(Value::Int(2)) => {
42            println!("pong replied 2 (Atomic Hop)");
43            println!("{metrics}");
44        }
45        other => {
46            eprintln!("unexpected {other:?}");
47            std::process::exit(1);
48        }
49    }
50}
More examples
Hide additional examples
examples/atomic_actors.rs (line 25)
21fn main() {
22    let chunk = samples::atomic_request_reply();
23    let rt = match Runtime::with_natives_and_config(
24        chunk,
25        std_native_table(),
26        RuntimeConfig {
27            workers: 2,
28            quantum: 10_000,
29        },
30    ) {
31        Ok(rt) => rt,
32        Err(e) => {
33            eprintln!("runtime: {e}");
34            std::process::exit(1);
35        }
36    };
37    let Some(main) = rt.function_index("main") else {
38        eprintln!("missing main");
39        std::process::exit(1);
40    };
41    let handle = match rt.spawn(main, &[]) {
42        Ok(h) => h,
43        Err(e) => {
44            eprintln!("spawn: {e}");
45            std::process::exit(1);
46        }
47    };
48    let outcome = handle.join();
49    let metrics = rt.metrics();
50    rt.shutdown();
51
52    match outcome {
53        FlowOutcome::Completed(Value::Int(42)) => {
54            println!("atomic request-reply ok: payload=42");
55            println!("{metrics}");
56        }
57        other => {
58            eprintln!("unexpected {other:?}");
59            std::process::exit(1);
60        }
61    }
62}