Function rune::prepare [−][src]
Expand description
Entry point to building Sources of Rune.
Uses the Source::name when generating diagnostics to reference the file.
Examples
Note: these must be built with the emit
feature enabled (default) to give
access to rune::termcolor
.
use rune::termcolor::{ColorChoice, StandardStream};
use rune::{Context, Options, Source, Vm};
use std::sync::Arc;
let context = Context::with_default_modules()?;
let runtime = Arc::new(context.runtime());
let mut sources = rune::Sources::new();
sources.insert(Source::new("entry", r#"
pub fn main() {
println("Hello World");
}
"#));
let mut diagnostics = rune::Diagnostics::new();
let result = rune::prepare(&mut sources)
.with_context(&context)
.with_diagnostics(&mut diagnostics)
.build();
if !diagnostics.is_empty() {
let mut writer = StandardStream::stderr(ColorChoice::Always);
diagnostics.emit(&mut writer, &sources)?;
}
let unit = result?;
let unit = Arc::new(unit);
let vm = Vm::new(runtime, unit);