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 mailbox: byteflow::MailboxConfig::DEFAULT,
18 },
19 ) {
20 Ok(rt) => rt,
21 Err(e) => {
22 eprintln!("runtime: {e}");
23 std::process::exit(1);
24 }
25 };
26 let Some(main) = rt.function_index("main") else {
27 eprintln!("missing main");
28 std::process::exit(1);
29 };
30 let handle = match rt.spawn(main, &[]) {
31 Ok(h) => h,
32 Err(e) => {
33 eprintln!("spawn: {e}");
34 std::process::exit(1);
35 }
36 };
37 let outcome = handle.join();
38 let metrics = rt.metrics();
39 rt.shutdown();
40
41 match outcome {
42 FlowOutcome::Completed(Value::Int(2)) => {
43 println!("pong replied 2 (Atomic Hop)");
44 println!("{metrics}");
45 }
46 other => {
47 eprintln!("unexpected {other:?}");
48 std::process::exit(1);
49 }
50 }
51}More 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 mailbox: byteflow::MailboxConfig::DEFAULT,
30 },
31 ) {
32 Ok(rt) => rt,
33 Err(e) => {
34 eprintln!("runtime: {e}");
35 std::process::exit(1);
36 }
37 };
38 let Some(main) = rt.function_index("main") else {
39 eprintln!("missing main");
40 std::process::exit(1);
41 };
42 let handle = match rt.spawn(main, &[]) {
43 Ok(h) => h,
44 Err(e) => {
45 eprintln!("spawn: {e}");
46 std::process::exit(1);
47 }
48 };
49 let outcome = handle.join();
50 let metrics = rt.metrics();
51 rt.shutdown();
52
53 match outcome {
54 FlowOutcome::Completed(Value::Int(42)) => {
55 println!("atomic request-reply ok: payload=42");
56 println!("{metrics}");
57 }
58 other => {
59 eprintln!("unexpected {other:?}");
60 std::process::exit(1);
61 }
62 }
63}