Struct evcxr::EvalContext
source · pub struct EvalContext { /* private fields */ }
Implementations§
source§impl EvalContext
impl EvalContext
sourcepub fn new() -> Result<(EvalContext, EvalContextOutputs), Error>
pub fn new() -> Result<(EvalContext, EvalContextOutputs), Error>
Examples found in repository?
examples/example_eval.rs (line 16)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fn main() -> Result<(), Error> {
// You must call ```evcxr::runtime_hook()``` at the top of main, otherwise
// the library becomes a fork-bomb.
evcxr::runtime_hook();
let (mut context, outputs) = EvalContext::new()?;
context.eval("let mut s = String::new();")?;
context.eval(r#"s.push_str("Hello, ");"#)?;
context.eval(r#"s.push_str("World!");"#)?;
context.eval(r#"println!("{}", s);"#)?;
// For this trivial example, we just receive a single line of output from
// the code that was run. In a more complex case, we'd likely want to have
// separate threads waiting for output on both stdout and stderr.
if let Ok(line) = outputs.stdout.recv() {
println!("{line}");
}
Ok(())
}
pub fn with_subprocess_command( subprocess_command: Command ) -> Result<(EvalContext, EvalContextOutputs), Error>
sourcepub fn state(&self) -> ContextState
pub fn state(&self) -> ContextState
Returns a new context state, suitable for passing to eval
after
optionally calling things like add_dep
.
sourcepub fn eval(&mut self, code: &str) -> Result<EvalOutputs, Error>
pub fn eval(&mut self, code: &str) -> Result<EvalOutputs, Error>
Evaluates the supplied Rust code.
Examples found in repository?
examples/example_eval.rs (line 17)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fn main() -> Result<(), Error> {
// You must call ```evcxr::runtime_hook()``` at the top of main, otherwise
// the library becomes a fork-bomb.
evcxr::runtime_hook();
let (mut context, outputs) = EvalContext::new()?;
context.eval("let mut s = String::new();")?;
context.eval(r#"s.push_str("Hello, ");"#)?;
context.eval(r#"s.push_str("World!");"#)?;
context.eval(r#"println!("{}", s);"#)?;
// For this trivial example, we just receive a single line of output from
// the code that was run. In a more complex case, we'd likely want to have
// separate threads waiting for output on both stdout and stderr.
if let Ok(line) = outputs.stdout.recv() {
println!("{line}");
}
Ok(())
}
pub fn eval_with_state( &mut self, code: &str, state: ContextState ) -> Result<EvalOutputs, Error>
pub fn hover( &mut self, code: &str, state: &mut ContextState ) -> Result<(String, String)>
pub fn last_source(&self) -> Result<String, Error>
pub fn set_opt_level(&mut self, level: &str) -> Result<(), Error>
pub fn set_time_passes(&mut self, value: bool)
pub fn set_preserve_vars_on_panic(&mut self, value: bool)
pub fn set_error_format(&mut self, value: &str) -> Result<(), Error>
pub fn variables_and_types(&self) -> impl Iterator<Item = (&str, &str)>
pub fn defined_item_names(&self) -> impl Iterator<Item = &str>
pub fn clear(&mut self) -> Result<(), Error>
pub fn reset_config(&mut self)
pub fn process_handle(&self) -> Arc<Mutex<Child>>
Auto Trait Implementations§
impl !RefUnwindSafe for EvalContext
impl Send for EvalContext
impl !Sync for EvalContext
impl Unpin for EvalContext
impl !UnwindSafe for EvalContext
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more