Skip to main content

render_value

Function render_value 

Source
pub fn render_value(value: &Value) -> String
Examples found in repository?
examples/run_file.rs (line 16)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut args = env::args_os();
8    let binary = args.next().unwrap_or_default();
9    let Some(path) = args.next().map(PathBuf::from) else {
10        eprintln!("usage: {} <program.rss>", PathBuf::from(binary).display());
11        std::process::exit(64);
12    };
13
14    let RunOutcome::Halted { stack } = run_source_file(&path)?;
15    if let Some(value) = stack.last() {
16        eprintln!("final: {}", render_value(value));
17    }
18
19    Ok(())
20}
More examples
Hide additional examples
examples/repl.rs (line 36)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    println!("RustScript embedded REPL (JIT off)");
7    println!("commands: .help, .quit");
8
9    let stdin = io::stdin();
10    let mut input = stdin.lock();
11    let mut line = String::new();
12
13    loop {
14        print!("rs-emb> ");
15        io::stdout().flush()?;
16        line.clear();
17        if input.read_line(&mut line)? == 0 {
18            println!();
19            break;
20        }
21
22        let source = line.trim();
23        match source {
24            "" => continue,
25            ".quit" | ".exit" => break,
26            ".help" => {
27                println!("enter RustScript statements, for example: print(1 + 2);");
28                continue;
29            }
30            _ => {}
31        }
32
33        match eval_repl_entry(source)? {
34            RunOutcome::Halted { stack } => {
35                if let Some(value) = stack.last() {
36                    println!("=> {}", render_value(value));
37                } else {
38                    println!("=> <empty>");
39                }
40            }
41        }
42    }
43
44    Ok(())
45}