Struct evcxr::EvalContext

source ·
pub struct EvalContext { /* private fields */ }

Implementations§

Examples found in repository?
examples/example_eval.rs (line 23)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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(())
}

Returns a new context state, suitable for passing to eval after optionally calling things like add_dep.

Evaluates the supplied Rust code.

Examples found in repository?
examples/example_eval.rs (line 24)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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(())
}

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Cast a value to type U using CastTo.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more