pub fn runtime_hook()Expand description
Binaries can call this just after staring. If we detect that we’re actually running as a subprocess, control will not return. There are two kinds of subprocesses that we may be acting as (1) the process that loads and runs the user code and (2) a wrapper around rustc.
Examples found in repository?
examples/example_eval.rs (line 14)
11fn main() -> Result<(), Error> {
12 // You must call ```evcxr::runtime_hook()``` at the top of main, otherwise
13 // the library becomes a fork-bomb.
14 evcxr::runtime_hook();
15
16 let (mut context, outputs) = EvalContext::new()?;
17 context.eval("let mut s = String::new();")?;
18 context.eval(r#"s.push_str("Hello, ");"#)?;
19 context.eval(r#"s.push_str("World!");"#)?;
20 context.eval(r#"println!("{}", s);"#)?;
21
22 // For this trivial example, we just receive a single line of output from
23 // the code that was run. In a more complex case, we'd likely want to have
24 // separate threads waiting for output on both stdout and stderr.
25 if let Ok(line) = outputs.stdout.recv() {
26 println!("{line}");
27 }
28
29 Ok(())
30}